import sys
import pcapy
from impacket import ImpactDecoder, ImpactPacket
import re
def main(argv):
try:
cap = pcapy.open_offline(argv[1])
(header, payload) = cap.next()
while header:
(seconds, micros) = header.getts()
# Parse the Ethernet packet
decoder = ImpactDecoder.EthDecoder()
ether = decoder.decode(payload)
# Parse the IP packet inside the Ethernet packet
iphdr = ether.child()
# Parse the TCP packet inside the IP packet
tcphdr = iphdr.child()
# Get the source and destination IP addresses
src_ip = iphdr.get_ip_src()
dst_ip = iphdr.get_ip_dst()
if tcphdr.child() <> None:
body = tcphdr.child().get_packet()
isFIX = re.match('8=FIX', body)
if isFIX <> None:
print "%d.%06d %s" % (seconds, micros, body)
(header, payload) = cap.next()
except pcapy.PcapError:
pass
if __name__ == "__main__":
main(sys.argv)
No comments:
Post a Comment