Reputation: 35662
this is my code :
import pcap ,struct
pack=pcap.pcap()
pack.setfilter('udp')
key=''
for recv_time,recv_data in pack:
recv_len=len(recv_data)
if recv_len == 102 and recv_data[42]== chr(02) and recv_data[101] == chr(03):
print struct.unpack('>I',recv_data[49:53])[0]
print '登陆了'
elif recv_len == 55:
print struct.unpack('>I',recv_data[49:53])[0]
print '登陆了'
and i use this to install pcap :sudo apt-get install python-libpcap
, it installed ,
but when i run the code , it show error :
Traceback (most recent call last):
File "weapon.py", line 2, in <module>
import pcap ,struct
ImportError: No module named pcap
what can i do ,
thanks
Upvotes: 1
Views: 20744
Reputation: 21
You need to make sure that you have pip installed.
sudo apt-get install python-pip
Then you can install pypcap:
sudo easy_install pypcap
sudo pip install pypcap
I verified it for Ubuntu 14.10.
Upvotes: 2
Reputation: 563
I'm guessing the installed module doesn't match the version of python you're running.
Look in /usr/lib/python2.7/dist-packages/
and see if pcap
is there (substituting the version you're using for 2.7).
Upvotes: 1
Reputation: 17960
For me on Ubuntu 10.04 the package is called python-libpcap:
sudo apt-get install python-libpcap
Then when I do:
import pcap
It works great!
Upvotes: 5