Esempio n. 1
0
def main():
    if len(sys.argv) != 2:
        if len(sys.argv) == 1:
            sys.argv.extend(['en1'])
            print 'using defaul args:', ' '.join(sys.argv)
        else:
            print 'usage: %s dev' % sys.argv[0]
            print '\tdev ... device'
            sys.exit(1)
    
    
    global LOCAL_DEVICE, LOCAL_MAC_ADDRESS, LOCAL_IP_ADDRESS, \
        REMOTE_MAC_ADDRESS, REMOTE_IP_ADDRESS
    
    LOCAL_DEVICE = sys.argv[1]
    
    if LOCAL_MAC_ADDRESS is None:
        LOCAL_MAC_ADDRESS = shared.get_local_mac_addres_of_device(LOCAL_DEVICE)
    
    fd = bpf.get_bpf_fg(device=LOCAL_DEVICE, promiscuous=False)
    
    dhcp_info = shared.request_dhcp_info(fd, LOCAL_MAC_ADDRESS)
    LOCAL_IP_ADDRESS = dhcp_info['yiaddr']
    
    for var_name in ('LOCAL_DEVICE', 'LOCAL_MAC_ADDRESS', 'LOCAL_IP_ADDRESS'):
        print "%-20s %s" % (var_name + ':', globals()[var_name])
    print
    
    pingd(fd)
    
    bpf.bpf_dispose(fd)
Esempio n. 2
0
def main():
    if len(sys.argv) != 2:
        if len(sys.argv) == 1:
            sys.argv.extend(['en1'])
            print 'using defaul args:', ' '.join(sys.argv)
        else:
            print 'usage: %s dev host' % sys.argv[0]
            print '\tdev ... device'
            sys.exit(1)
    
    global LOCAL_DEVICE, LOCAL_MAC_ADDRESS, raw_packet
    LOCAL_DEVICE = sys.argv[1]
    LOCAL_MAC_ADDRESS = shared.get_local_mac_addres_of_device(LOCAL_DEVICE)
    print 'LOCAL_MAC_ADDRESS: %s' % LOCAL_MAC_ADDRESS
    
    fd = bpf.get_bpf_fg(device=LOCAL_DEVICE)
    
    for bpf_packet in bpf.packet_reader(fd):
        raw_packet = bpf_packet.data
        eth_packet_callback(Ethernet(bpf_packet.data))

    bpf.bpf_dispose(fd)
Esempio n. 3
0
def main():
    if len(sys.argv) != 3:
        if len(sys.argv) == 1:
            sys.argv.extend(['en1', '192.168.1.1'])
            print 'using defaul args:', ' '.join(sys.argv)
        else:
            print 'usage: %s dev host' % sys.argv[0]
            print '\tdev ... device'
            print '\thost ... ip address of host'
            sys.exit(1)
    
    global LOCAL_DEVICE, LOCAL_MAC_ADDRESS, LOCAL_IP_ADDRESS, \
        REMOTE_MAC_ADDRESS, REMOTE_IP_ADDRESS
    
    LOCAL_DEVICE = sys.argv[1]
    LOCAL_MAC_ADDRESS = shared.get_local_mac_addres_of_device(LOCAL_DEVICE)
    REMOTE_IP_ADDRESS = IPAddress(str_val=sys.argv[2])
    
    fd = bpf.get_bpf_fg(device=LOCAL_DEVICE)
    
    dhcp_info = shared.request_dhcp_info(fd, LOCAL_MAC_ADDRESS)
    
    LOCAL_IP_ADDRESS = dhcp_info['yiaddr']
    SUBNET_MASK = dhcp_info['subnet_mask']
    
    if SUBNET_MASK.addresses_in_same_subnet(LOCAL_IP_ADDRESS, REMOTE_IP_ADDRESS):
        NEXT_HOOP_IP_ADDRESS = REMOTE_IP_ADDRESS
    else:
        NEXT_HOOP_IP_ADDRESS = dhcp_info['router']

    REMOTE_MAC_ADDRESS = shared.request_adp_mac_addres(fd, LOCAL_MAC_ADDRESS, LOCAL_IP_ADDRESS, NEXT_HOOP_IP_ADDRESS)
    
    for var_name in ('LOCAL_DEVICE', 'LOCAL_MAC_ADDRESS', 'LOCAL_IP_ADDRESS', 'REMOTE_MAC_ADDRESS', 'REMOTE_IP_ADDRESS'):
        print "%-20s %s" % (var_name + ':', globals()[var_name])
    
    ping(fd)
    
    bpf.bpf_dispose(fd)
Esempio n. 4
0
                in_arp = ARP(parent=in_eth)
                
                if in_arp.htype == 0x0001 \
                    and in_arp.ptype == 0x0800 \
                    and in_arp.hlen == 0x0006 \
                    and in_arp.plen == 0x0004 \
                    and in_arp.oper == 0x0002 \
                    and in_arp.spa == remote_ip_address \
                    and in_arp.tha == local_mac_address \
                    and in_arp.tpa == local_ip_address:
                    
                    return in_arp.sha
            
    except bpf.BPFTimeout:
        print 'request_adp_mac_addres(local_mac_address=%s, local_ip_address=%s, remote_ip_address=%s) timed out!' % (
            local_mac_address, local_ip_address, remote_ip_address)
        sys.exit(1)
    
if __name__ == '__main__':
    LOCAL_DEVICE = 'en1'
    REMOTE_IP_ADDRESS = IPAddress(str_val='192.168.1.1')
    LOCAL_MAC_ADDRESS = get_local_mac_addres_of_device(LOCAL_DEVICE)
    
    fd = bpf.get_bpf_fg(device=LOCAL_DEVICE)
    
    LOCAL_IP_ADDRESS = request_dhcp_info(fd, LOCAL_MAC_ADDRESS)['yiaddr']
    
    print request_adp_mac_addres(fd, LOCAL_MAC_ADDRESS, LOCAL_IP_ADDRESS, REMOTE_IP_ADDRESS)
    
    bpf.bpf_dispose(fd)