I receive in real-time a list of raw packets (bytes) and I want to parse them into scapy without having to write and read them from a pcap.
Here the answer is to use Ether if the first layer is Ether, but what if not?
For example:
>>> pkt.layers()
>>> [scapy.layers.inet6.IPv6, scapy.layers.inet.TCP]
>>> pkt.build()
>>> b'`\x00\x00\x00\x00(\x06@ \x01\x06\x18\x04\x00\x00\x00\x00\x00\x00\x00Q\x99\xccp \x01\x06\x18\x00\x01\x80\x00\x00\x00\x00\x00\x00\x00\x00\x05\x8c\x9b\x00Pj\xe7\x076\x00\x00\x00\x00\xa0\x02\x160)\x9c\x00\x00\x02\x04\x05\x8c\x04\x02\x08\n\x00\xdd\x1a9\x00\x00\x00\x00\x01\x03\x03\x02'
I can't use Ether(pkt)
since pkt
has no Ether
layer.
But if I write the packet to a pcap file and read it again I can parse it.
>>> wrpcap("/tmp/proof.pcap", pkt)
>>> pcap = rdpcap("/tmp/proof.pcap")
>>> type(pcap[0])
scapy.layers.inet6.IPv6
How could I parse packets like wrpcap-rdpcap
without writing and reading files all time?