Scapy:如何访问自定义数据包的RAW

时间:2015-02-24 08:56:55

标签: python scapy

我正在尝试访问此数据包的RAW数据。我不知道如何提取它并将其存储在变量中。我尝试过使用getlayer方法,但它没有返回Raw有效负载。

>>> b.show2()
###[ LSP Object ]###
  \common_object_header\
   |###[ PCEP Common Object Header ]###
   |  oclass= LSP
   |  oType= 1L
   |  resflags=
   |  pflag=
   |  iflag=
   |  obLength= 20
  plspid= 0x1L
  flag= 0L
  Cflag=
  oflag= DOWN
  Aflag=
  Rflag=
  Sflag=
  Dflag= D
  \symbolic_path_name\
   |###[ symbolic_path_name_tlv ]###
   |  tlvType= SYMBOLIC-PATHNAME-TLV
   |  tlvLength= 5
   |  tlvValue= 'lsp12'
   |###[ Raw ]###
   |     load= '000' <---- How to access this field???
>>>

>>> b.symbolic_path_name.getlayer(Raw) <--- This does'nt return anything
>>>
>>>
>>> b.symbolic_path_name.getlayer(Raw).load
Traceback (most recent call last):
  File "<console>", line 1, in <module>
AttributeError: 'NoneType' object has no attribute 'load'
>>>                                                                                                                                                                                    

1 个答案:

答案 0 :(得分:0)

所以我认为Raw对象是最后一层,代表有效载荷。 所以你可以直接访问它

last = b.getlayer(Raw)
# Because Raw is last this works as well, e.g. No Padding
last2 = b.lastlayer()
print last.load
print last2.load