如何使用 python 在 ubuntu 中安装 pcap
这是我的代码:
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 '登陆了'
我用它来安装 pcap:sudo apt-get install python-libpcap
,它已安装,
但是当我运行代码时,它显示错误:
Traceback (most recent call last):
File "weapon.py", line 2, in <module>
import pcap ,struct
ImportError: No module named pcap
我能做什么,
谢谢
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
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
对于 Ubuntu 10.04 上的我来说,该软件包称为 python-libpcap:
然后当我这样做时:
它工作得很好!
For me on Ubuntu 10.04 the package is called python-libpcap:
Then when I do:
It works great!
您需要确保已安装 pip。
然后就可以安装pypcap了:
我在Ubuntu 14.10上验证了它。
You need to make sure that you have pip installed.
Then you can install pypcap:
I verified it for Ubuntu 14.10.
我猜安装的模块与您正在运行的 python 版本不匹配。
查看
/usr/lib/python2.7/dist-packages/
并查看是否有pcap
(用您正在使用的版本替换 2.7)。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 ifpcap
is there (substituting the version you're using for 2.7).