本文介绍了如何腌制一个鱼鳞状的小包?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要腌制一个scapy数据包.在大多数情况下,这是可行的,但有时,选择器会抱怨函数对象.根据经验:ARP数据包可以腌制.某些UDP数据包有问题.

I need to pickle a scapy packet. Most of the time this works, but sometimes the pickler complains about a function object. As a rule of thumb: ARP packets pickle fine. Some UDP packets are problematic.

推荐答案

我的解决方案(受scapy邮件列表的启发)如下:

My solution (as inspired by the scapy mailing list) is as follows:

class PicklablePacket:
    """A container for scapy packets that can be pickled (in contrast
    to scapy packets themselves)."""
    def __init__(self, pkt):
        self.contents = bytes(pkt)
        self.time = pkt.time

    def __call__(self):
        """Get the original scapy packet."""
        pkt = scapy.Ether(self.contents)
        pkt.time = self.time
        return pkt

我希望通过Queue传递scapy Packet的任何地方,我只需将其包装在PicklablePacket中,然后将其包装在__call__中.我不知道没有以这种方式保留的数据.但是,此方法仅适用于Ethernet数据包. (在常规NIC(不是WLAN)上嗅探到的所有数据包都是以太网.)它可能也可以扩展为适用于其他类型.

Anywhere I wish to pass a scapy Packet through a Queue I simply wrap it in a PicklablePacket and __call__ it afterwards. I am not aware of data that is not retained this way. However this approach only works with Ethernet packets. (All packets sniffed on a regular NIC (not WLAN) are Ethernet.) It could probably be extended to work for other types, too.

这篇关于如何腌制一个鱼鳞状的小包?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-05 19:13