Created
October 16, 2012 09:28
-
-
Save hahastudio/3898292 to your computer and use it in GitHub Desktop.
python pcap file analyse
This file contains 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
from pcapy import open_offline | |
def filter_HTTPGET(packet): | |
if packet[0x33] == '\x06' and packet[0x52:0x56] == "GET ":#tcp and tcp[20:4] = 0x47455420 | |
return True | |
return False | |
def get_source_IP(packet): | |
#return '.'.join(str(ord(i)) for i in packet[0x36:0x3A]) | |
return tuple(ord(i) for i in packet[0x36:0x3A]) | |
classA, classB, classC = 0, 0, 0 | |
#source_IP_file = open("sip", 'w') | |
pc = open_offline("ttt.pcap") | |
data = pc.next() | |
while data[0]: | |
if filter_HTTPGET(data[1]): | |
#source_IP_file.write(get_source_IP(data[1])+'\n') | |
sourceIP = get_source_IP(data[1]) | |
if sourceIP[0] < 128: | |
classA += 1 | |
elif sourceIP[0] < 192: | |
classB += 1 | |
elif sourceIP[0] < 224: | |
classC += 1 | |
data = pc.next() | |
print classA, classB, classC | |
#source_IP_file.close() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment