Beispiel #1
0
 def setupPcap(self):
     device = libpcap.pcap_findalldevs()[0]
     self.pcap = libpcap.pcap_open_live(device, self.snaplen, self.promisc,
                                        self.to_ms)
     bpf = libpcap.bpf_program()
     libpcap.pcap_compile(self.pcap, self.pcap_filter, bpf)
     libpcap.pcap_setfilter(self.pcap, bpf)
Beispiel #2
0
def forever():
    try:
        handle = libpcap.pcap_open_live(DEVICE, SNAPLEN, PROMISC, TIMEOUT_MS)
        if handle:
            bpf = libpcap.bpf_program()
            libpcap.pcap_compile(handle, BPF_FILTER, bpf)
            libpcap.pcap_setfilter(handle, bpf)
            while 1:
                pkt_hdr, pkt_data = libpcap.pcap_next(handle)
                packet = libpcap.Packet(pkt_hdr, pkt_data)
                processPackets(packet)
    except KeyboardInterrupt:
        print "Trap Ctrl+C."
        print "Exiting..."
        sys.exit(0)
Beispiel #3
0
def forever():
    try:
        handle = libpcap.pcap_open_live(DEVICE, SNAPLEN, PROMISC, TIMEOUT_MS)
        if handle:
            bpf = libpcap.bpf_program()
            libpcap.pcap_compile(handle, BPF_FILTER, bpf)
            libpcap.pcap_setfilter(handle, bpf)
            while(1):
                pkt_hdr, pkt_data = libpcap.pcap_next(handle)
                packet = libpcap.Packet(pkt_hdr, pkt_data)
                processPackets(packet)
    except KeyboardInterrupt:
        print "Trap Ctrl+C."
        print "Exiting..."
        sys.exit(0)