You have two options: the operator inis one.
>>> TCP in pkt
True
>>> if TCP in pkt:
...
Batch objects in Scapy also have a function named haslayer().
>>> pkt = IP()/TCP()
>>> pkt.haslayer(TCP)
1
>>> pkt2 = IP()/UDP()
>>> pkt2.haslayer(TCP)
0
>>> Packet.haslayer.__doc__
'true if self has a layer that is an instance of cls. Superseded by "cls in self" syntax.'
source
share