]> git.somenet.org - pub/jan/netsec2.git/blob - exercise2/task2/somedecode.py
GITOLITE.txt
[pub/jan/netsec2.git] / exercise2 / task2 / somedecode.py
1 #!/usr/bin/env python
2
3 import csv
4 import binascii
5
6 def somedecode(filename):
7   with open(filename, 'rb') as csvfile:
8     spamreader = csv.reader(csvfile, delimiter=',', quotechar='"')
9     header = None
10     bits = ""
11     
12     for row in spamreader:
13       if header is None:
14         header = row
15         continue
16
17       if row[12] == 'ICMP':
18         bits += "0"
19       if row[12] == 'UDP':
20         bits += "1"
21
22 #    print bits
23     #bits = bits[:-(len(bits)%8)]
24     print binascii.unhexlify('%x' % int(bits, 2))
25
26 if __name__ == "__main__":
27         somedecode("flow_204.10.110.7_187.10.25.137.csv")
28