如何停止按用户要求嗅探
因此,我正在编写一个代码,需要嗅探,直到用户按CTRL C,模仿Scapy中的Sniff()功能。我尝试了许多不同的方法,但它们无法正常工作。
此处代码的一部分:
def stop_sniff_user(sig, frame):
print("You pressed Ctrl + C")
exit(0)
signal.signal(signal.SIGINT, stop_sniff_user)
packets = sniff()
while True:
pass
它给出了此警告:
警告:插座< scapy.arch.pcapdnet.l2pcaplistensocket对象在0x0CBBC580> '呼叫()失败了1个位置论点,但给出了2个。它已关闭。
我也尝试使用键盘插入异常,但是我很确定我也不知道如何正确使用它。
我该怎么做?
so I'm writing a code where I need to sniff until the user presses Ctrl C, imitating the sniff() function in scapy. I've tried many different ways but they won't work.
a part of the code here:
def stop_sniff_user(sig, frame):
print("You pressed Ctrl + C")
exit(0)
signal.signal(signal.SIGINT, stop_sniff_user)
packets = sniff()
while True:
pass
and it gives this warning:
WARNING: Socket <scapy.arch.pcapdnet.L2pcapListenSocket object at 0x0CBBC580> failed with 'call() takes 1 positional argument but 2 were given'. It was closed.
i've tried also using the KeyboardInterrupt exception, but Im pretty sure I don't know how to use it right also.
how do I do it right?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
Scapy嗅觉功能来自异步类别。您可以像嗅探函数一样创建异步对象并将参数传递到其中。然后调用该对象start()和join()函数,当捕获异常键盘间断时,只需调用stop(),它将返回数据包。根据您的代码,它看起来像
Scapy sniff function is from AsyncSniffer class. You can create AsyncSniffer object and pass the parameters into it just like in the sniff function. Then call on that object start() and join() functions and when exception KeyboardInterrupt is catched just call stop() which will return the packets. Based on your code it would look like