Skip to content

Instantly share code, notes, and snippets.

@elvinio
Created October 5, 2015 09:40
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save elvinio/6d6e2a947523f5a2d3c0 to your computer and use it in GitHub Desktop.
Save elvinio/6d6e2a947523f5a2d3c0 to your computer and use it in GitHub Desktop.
#!/usr/bin/python
from struct import *
with open('cap','rb') as f:
data = f.read(24)
globalHeader = unpack('IHHiIII',data)
print globalHeader
data = f.read(16)
while data != "":
packetHeader = unpack('IIII', data)
data = f.read(packetHeader[3])
if data == "":
break
#Eth 14 bytes, IP 20 bytes, UDP 8 bytes
sbe = data[42:]
if len(sbe) > 16:
# Seq num, sending time
sbeHeader = unpack_from('IQ', sbe, 0)
# message size, block len, template id, schema id, version
sbeMsg = unpack_from('HHHHH', sbe, 12)
if sbeMsg[2] == 32:
# transact time, match event indic, MD Entries
sbeFix = unpack_from('QB', sbe, 22)
# px, size, sec id, rpt seq, numof order, price level, update action, entry type
# block length is 11 so add 10.
sbeMDEntries = unpack_from('qiiIiBBB', sbe, 32)
print sbeMsg, sbeFix, sbeMDEntries
data = f.read(16)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment