pynetwork / pypcap

pypcap - python libpcap module, forked from code.google.com/p/pypcap
Other
299 stars 74 forks source link

'NoneType' object is not iterable #56

Closed rootkiter closed 6 years ago

rootkiter commented 7 years ago

I'm fresh.and I write the command like this..but an exception throw out.

$ sudo apt-get install libpcap-dev python-dev
$ sudo pip install pypcap
$ cat sniffer.py
#!/bin/python
## copy from README.txt
import sys,pcap
if __name__=='__main__':
    try:
        sniffer = pcap.pcap (name=None,promisc = True, immediate=True)
        addr = lambda pkt, offset: '.'.join(str(ord(pkt[i])) for i in xrange(offset, offset + 4)).ljust(16)
        print "Hello World ! ",str(addr)
        for ts, pkt in sniffer:
            print ts, '\tSRC', addr(pkt, sniffer.dloff + 12), '\tDST', addr(pkt, sniffer.dloff + 16)
    except  Exception as e:
        print str(e)

$ sudo python sniffer.py 
Hello World !  <function <lambda> at 0x7f1c93d85500>
'NoneType' object is not iterable
$ 

So, why the exception?

rootkiter commented 7 years ago

$ uname -a Linux ubuntu 3.16.0-30-generic #40~14.04.1-Ubuntu SMP Thu Jan 15 17:43:14 UTC 2015 x86_64 x86_64 x86_64 GNU/Linux

liuyangc3 commented 6 years ago

change name=None to NIC iterface name like name='eth0'

hellais commented 6 years ago

Yes what @liuyangc3 says should resolve your problem. Let me us know if that is not the case.