如何检查 scapy 数据包中是否存在图层?
如何检查 scapy 数据包中是否存在特定层?例如,我需要检查 IP 标头的 src/dst 字段,我如何知道特定数据包实际上具有 IP 标头(例如与 IPv6 相对)。
我的问题是,当我去检查 IP 标头字段时,收到一条错误消息,指出 IP 层不存在。这个特定的数据包没有 IP 标头,而是 IPv6。
pkt = Ether(packet_string)
if pkt[IP].dst == something:
# do this
当我尝试引用 IP 层时发生错误。在尝试操作该层之前如何检查该层是否存在?
谢谢!
How do I check for the presence of a particular layer in a scapy packet? For example, I need to check the src/dst fields of an IP header, how do I know that a particular packet actually has an IP header (as opposed to IPv6 for instance).
My problem is that when I go to check for an IP header field, I get an error saying that the IP layer doesn't exist. Instead of an IP header, this particular packet had IPv6.
pkt = Ether(packet_string)
if pkt[IP].dst == something:
# do this
My error occurs when I try to reference the IP layer. How do I check for that layers existence before attempting to manipulate it?
Thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您应该尝试
in
运算符。它返回True
或False
,具体取决于Packet
中是否存在该层。You should try the
in
operator. It returnsTrue
orFalse
depending if the layer is present or not in thePacket
.为了完整起见,我想我还要提到
haslayer
方法。希望这也有帮助。
For completion I thought I would also mention the
haslayer
method.Hope that helps as well.