我发现了一些关于对象删除自身的问题。但没有提到需要采取这种行动的适当例子。但以下面的例子为例。
from scapy.all import *
class x():
def me(self):
self.i=0
sniff(iface="em1", filter='tcp', prn=self.my_callback)
def my_callback(self, pkt):
print pkt.summary()
self.i+=1
if self.i>10:
self.__del__()
def __del__(self):
print self
return
y=x()
y.me()
print y
在这种情况下,sniff
函数将无限继续。如果收到10 pkts
,我想停止它并删除object
。因此,应该从内部开始删除对象。
我该怎么做?
如果目标是在从特定IP接收特定数据包时停止
sniff
,则正确的方法是将stop_filter
传递给sniff
函数,如下面复制的文档中所指定。下面是一些示例代码,可以停止对来自特定IP的数据包的嗅探。
这里的解决办法不是摧毁这个物体。如果你以某种方式摧毁了这个物体,当它试图使用一个被摧毁的物体时,scapy就会崩溃或者做一些疯狂的事情。
相关问题 更多 >
编程相关推荐