August 2018
Intermediate to advanced
366 pages
10h 14m
English
The steps for this recipe are as follows:
The Python struct module is the perfect tool for reading binary-structured data and we can use it to parse our TCP packet as we know the size of each piece:
>>> import struct
>>> with open('/tmp/packet.dump', 'rb') as f:
... data = struct.unpack_from('>HHLL', f.read())
>>> data
(50291, 80, 2778997212, 644363807)
Being an HTTP connection, the result is what we would expect: Source Port: 50291, Destination Port: 80, Sequence Number: 2778997212, and Acknowledgment Number: 644363807.