Esempio n. 1
4
def tcpdump():
    parser = argparse.ArgumentParser(description='tcpdump')
    #parser.add_argument('filter', type=str, help="Specifies filter")
    parser.add_argument('-i', metavar='interface', dest='interface', required=True, type=str, help="Specifies the interface listen on")
    args = parser.parse_args()
    
    try:
        index = int(args.interface)
    except ValueError:
        device = args.interface
    else:   
        dev_names = []
        alldevs = pcap.pcap_findalldevs()
        dev = alldevs 
        while True:
            if not dev:
                break
            dev_names.append(dev.contents.name.decode())
            dev = dev.contents.next
        device = dev_names[index]
        pcap.pcap_freealldevs(alldevs)
    
    hpcap = pcap.pcap_open_live(device, 65535, False, 0)
    pf = pcap.pcap_compile(hpcap, 'icmp', False, 0)
    #pcap.pcap_setfilter(hpcap, pf)
#    #pcap.pcap_freecode(pf)
    pcap.pcap_loop(hpcap, -1, callback, None)
Esempio n. 2
0
#             libpcap.pcap_set_rfmon(self.hpcap, False)
#             libpcap.pcap_set_rfmon(self.hpcap, True)
# 
#     def test_pcap_set_timeout(self):
#         libpcap.pcap_set_timeout(self.hpcap, 1000*100)
# 
#     def test_pcap_set_buffer_size(self):
#         libpcap.pcap_set_buffer_size(self.hpcap, 1024*1024*1024)


if __name__ == '__main__':
    dev_names = []
    alldevs = pcap.pcap_findalldevs()
    dev = alldevs 
    while True:
        if not dev:
            break
        dev_names.append(dev.contents.name.decode())
        print(len(dev_names)-1, dev_names[-1])
        dev = dev.contents.next
    interface = input('which interface will be used for test? ')
    try:
        index = int(interface)
    except ValueError:
        print('error:should input the index of interface')
        sys.exit(-1)
    device = dev_names[index]
    pcap.pcap_freealldevs(alldevs)
    unittest.main()
    
Esempio n. 3
0
#         can_set_rfmon = libpcap.pcap_can_set_rfmon(self.hpcap)
#         if can_set_rfmon:
#             libpcap.pcap_set_rfmon(self.hpcap, False)
#             libpcap.pcap_set_rfmon(self.hpcap, True)
#
#     def test_pcap_set_timeout(self):
#         libpcap.pcap_set_timeout(self.hpcap, 1000*100)
#
#     def test_pcap_set_buffer_size(self):
#         libpcap.pcap_set_buffer_size(self.hpcap, 1024*1024*1024)

if __name__ == '__main__':
    dev_names = []
    alldevs = pcap.pcap_findalldevs()
    dev = alldevs
    while True:
        if not dev:
            break
        dev_names.append(dev.contents.name.decode())
        print(len(dev_names) - 1, dev_names[-1])
        dev = dev.contents.next
    interface = input('which interface will be used for test? ')
    try:
        index = int(interface)
    except ValueError:
        print('error:should input the index of interface')
        sys.exit(-1)
    device = dev_names[index]
    pcap.pcap_freealldevs(alldevs)
    unittest.main()