Created
November 10, 2012 16:20
-
-
Save prongs/4051536 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import re | |
from scapy.all import * | |
def psize(packet): | |
#assume 20 from http://stackoverflow.com/questions/6639799/calculate-size-and-start-of-tcp-packet-data-excluding-header | |
return packet[IP].len-packet[IP].ihl*4-4*packet[TCP].dataofs | |
def groupPacketsByFlow(packets): | |
flows={} | |
print flows | |
print type(packets) | |
for i in xrange(len(packets)): | |
packet=packets[i] | |
print packet | |
print type(packet) | |
print packet[IP] | |
return | |
pair = (packet[IP].src, packets[IP].dst) | |
print pair | |
if pair in flows: | |
print "in if" | |
flows[(packet[IP].src, packets[IP].dst)].append(packet) | |
else: | |
flows[(packet[IP].src, packets[IP].dst)] = [packet] | |
return flows | |
def analyzePcap(pcap): | |
packets=rdpcap(pcap) | |
print len(packets) | |
tcp_packets=filter(lambda p:p.haslayer(TCP),packets) | |
print len(tcp_packets) | |
flows = groupPacketsByFlow(tcp_packets) | |
if __name__=="__main__": | |
analyzePcap('proper.pcap') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment