Advertisement
dc5553

Pcap parse with scapy

Jan 24th, 2012
785
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.51 KB | None | 0 0
  1. #!/usr/bin/python
  2.  
  3. from scapy import *
  4. import sys
  5. from datetime import datetime
  6.  
  7. def flow_it(pkt):
  8.     snifftime = datetime.fromtimestamp(pkt.time).strftime('%Y-%m-%d %H:%M:%S').split(' ')[1]
  9.     print ' '.join([snifftime, ' '.join(pkt.summary().split(' ')[4:9])])
  10.        
  11. if '-l' in sys.argv:
  12.     sniff(prn=flow_it)
  13. else:
  14.     pkts = rdpcap(sys.argv[1])
  15.     print(' '.join(['Date: ',datetime.fromtimestamp(pkts[0].time).strftime('%Y-%m-%d %H:%M:%S').split(' ')[0]]))
  16.     for pkt in pkts:
  17.        flow_it(pkt)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement