我想知道如何验证从Scapy的sr1()
函数接收到的数据包包含TCP层,以便对TCP标志进行一些处理。
最佳答案
您有两个选择,in
运算符是一个。
>>> TCP in pkt
True
>>> if TCP in pkt:
... # Handle TCP Flags
Scapy中的数据包对象还具有称为
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.'
关于scapy - 如何验证Scapy中的数据包是否具有TCP层,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22093971/