]> git.somenet.org - pub/jan/netsec2.git/blob - exercise1/task2/somedecode.py
add decoder
[pub/jan/netsec2.git] / exercise1 / task2 / somedecode.py
1 #!/usr/bin/env python
2
3 import sys
4 import os
5 import signal
6 import csv
7 import binascii
8
9
10 def bladecode(filename):
11   with open(filename, 'rb') as csvfile:
12     spamreader = csv.reader(csvfile, delimiter=',', quotechar='"')
13     header = None
14     last = None
15     ln = 0
16     v = ""
17     
18     for row in spamreader:
19       if header is None:
20         header = row
21         continue
22       if last is None:
23         last = row
24         continue
25       
26       # if source != 192.168.67.84
27       if row[2] != '192.168.67.84':
28         continue
29
30       from pprint import pprint
31       #pprint("SRC: %s, DSCP: %s" % (row[2], row[10]))
32       #pprint ('diff:%f' % (float(row[1])-float(last[1])))
33       #va = str(int((float(row[1])-float(last[1]))*10))
34       va = str(int(row[10])-int(last[10]))
35       pprint ("diff:%s" % va)
36 #      print row[0]+"-"+row[1]+"-"+row[10]
37 #      print str(float(row[1])-float(last[1]))+"-"+str(int(row[10])-int(last[10]))
38       #print " "+str(unichr(int(row[10])-int(last[10])+ord('A'))),
39 #      va = str(int((float(row[1])-float(last[1]))*10))
40       if va not in ["0","1","2","3"]:
41         print "error: %s" % va
42         va = "1"
43
44       v = v+va
45       
46       ln += 1
47       if ln == 8:
48 #        print "char: "+v
49 #x        n = int(v, 2)
50 #        print(chr(n))
51 #        print "dec: "+binascii.unhexlify('%x' % n)
52 #        print " "+binascii.unhexlify('%x' % n),
53         v = ""
54 #        print ""
55         ln = 0
56       last = row
57
58 if __name__ == "__main__":
59         def signal_handler(signal, frame):
60                 print('SIG received. exitting!')
61                 sys.exit(0)
62         signal.signal(signal.SIGINT, signal_handler)
63
64         bladecode("10mins_transaction.dehexed.csv")
65