0000 00 01 00 14 45 49 50 43 A8 2A 55 50 6F 72 74 20 [37m.[0m[37m.[0m[37m.[0m[37m.[0mEIPC[37m.[0m*UPort
0010 49 64 20 3D 20 34 33 30 35 30 2A 2A 2A 2A 2A 2A Id = 43050******
0020 2A 2A 2A 2A 2A 2A 2A 2A 2A 2A 2A 2A 2A 2A 2A 2A ****************
0030 2A 2A 2A 2A 2A 2A 2A 2A 2A 2A 2A 2A 2A 2A 2A 2A ****************
0040 2A 2A 2A 2A 2A 2A 2A 2A 2A 2A 2A 2A 2A 2A 2A 2A ****************
0050 2A 2A 2A 2A 2A 2A 2A 2A 2A 2A 2A 2A 2A 2A 2A 2A ****************
0060 2A 2A 2A 2A 2A 2A 2A 2A 2A 2A 2A 2A 2A 2A 2A 2A ****************
0070 2A 2A 开发者_运维百科2A 2A 2A 2A 2A 2A 2A 2A 2A 2A 2A 2A 2A 2A ****************
0080 2A 2A 2A 2A 2A 2A 2A 2A 2A 2A 2A 2A 2A 2A 2A 2A ****************
This is my hexdump of a received packet, of which I just need -
UPort Id = 43050
******
****************
****************
****************
****************
****************
****************
****************
That is basically my payload, how can I get it?
You can use import_hexcap() and paste your hexdump into stdin. Replace IP() with whatever packet class you want to parse:
>>> pkt_hex = IP(import_hexcap())
0000 00 01 00 14 45 49 50 43 A8 2A 55 50 6F 72 74 20 [37m.[0m[37m.[0m[37m.[0m[37m.[0mEIPC[37m.[0m*UPort
0010 49 64 20 3D 20 34 33 30 35 30 2A 2A 2A 2A 2A 2A Id = 43050******
0020 2A 2A 2A 2A 2A 2A 2A 2A 2A 2A 2A 2A 2A 2A 2A 2A ****************
0030 2A 2A 2A 2A 2A 2A 2A 2A 2A 2A 2A 2A 2A 2A 2A 2A ****************
0040 2A 2A 2A 2A 2A 2A 2A 2A 2A 2A 2A 2A 2A 2A 2A 2A ****************
0050 2A 2A 2A 2A 2A 2A 2A 2A 2A 2A 2A 2A 2A 2A 2A 2A ****************
0060 2A 2A 2A 2A 2A 2A 2A 2A 2A 2A 2A 2A 2A 2A 2A 2A ****************
0070 2A 2A 2A 2A 2A 2A 2A 2A 2A 2A 2A 2A 2A 2A 2A 2A ****************
0080 2A 2A 2A 2A 2A 2A 2A 2A 2A 2A 2A 2A 2A 2A 2A 2A ****************
>>> pkt_hex
<IP version=0L ihl=0L tos=0x1 len=20 id=17737 flags=DF frag=4163L ttl=168 proto=42 chksum=0x5550 src=111.114.116.32 dst=73.100.32.61 options=[<IPOption_EOL copy_flag=0L optclass=1L option=end_of_list |>, <IPOption_Router_Alert copy_flag=0L optclass=1L option=router_alert length=51 alert=12341 |>, <IPOption copy_flag=0L optclass=1L option=imi_traffic_descriptor length=42 value='****************************************' |>, <IPOption copy_flag=0L optclass=1L option=experimental_measurement length=42 value='****************************************' |>, <IPOption copy_flag=0L optclass=1L option=experimental_measurement length=42 value='*************' |>] |<Raw load='********************' |>>
>>>
Are you looking to get just the port number?
>>> import re
>>> data = '\x00\x01\x00\x14\x45\x49\x50\x43\xA8\x2A\x55\x50\x6F\x72\x74\x20\x49\x64\x20\x3D\x20\x34\x33\x30\x35\x30\x2A\x2A\x2A\x2A\x2A\x2A'
>>> print re.findall('UPort Id = (\d*)', data)[0]
43050
>>>
精彩评论