开发者

Python: Scapy: How to read IP flags

I am trying to figure out how to read IP flags (not TCP) using scapy library. I know it is st开发者_StackOverflow社区ored in "flags" and it is FlagsField type. According to IP protocol specification there are 3 flags R, MF, and DF. I've search, and searched and could not find any info on how to read these flags. Any ideas?

Thank you all for your input.


For example, creating an IP packet with the DF (Don't Fragment) flag set:

>>> packet = IP(flags=2)  # alternatively, IP(flags='DF')
>>> packet
<IP  flags=DF |>

Reading a packet's flags:

>>> packet.flags
2

As for the flag bits, Wikipedia outlines this succinctly. It's a three-bit value with the following meaning:

  • bit 0: Reserved; must be zero.
  • bit 1: Don't Fragment (DF)
  • bit 2: More Fragments (MF)
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜