def parse_ip4(pack):
arr = struct_ip4.unpack(pack[:20])
hdr = {
"version" : arr[0] >> 4, # should be 4 ...
"ihl" : arr[0] & 0xF,
"tos" : arr[1],
"tot_len" : arr[2],
"id" : arr[3],
"frag_off" : arr[4],
"ttl" : arr[5],
"protcol" : arr[6],
"check" : arr[7],
"saddr" : ipaddress.IPv4Address(arr[8]),
"daddr" : ipaddress.IPv4Address(arr[9])
}
hdr_len = hdr["ihl"] * 4
return hdr, pack[hdr_len:]
评论列表
文章目录