]> git.somenet.org - pub/jan/netsec2.git/blob - exercise1/task1/somedecode.py
updates
[pub/jan/netsec2.git] / exercise1 / task1 / 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       #print row[0]+"-"+row[10]
27       #print str(int((float(row[1])-float(last[1]))*10))+"-"+str(int(row[10])-int(last[10]))
28       #print " "+str(unichr(int(row[10])-int(last[10])+ord('A'))),
29       va = str(int((float(row[1])-float(last[1]))*10))
30       if va not in ["0","1"]:
31         #print "error: "+va+row[0]+"-"+row[10]
32         va = "1"
33
34       v = v+va
35       
36       ln += 1
37       if ln == 8:
38 ##        print "char: "+v
39         n = int(v, 2)
40 #        print "dec: "+binascii.unhexlify('%x' % n)
41         print " "+binascii.unhexlify('%x' % n),
42         v = ""
43 #        print ""
44         ln = 0
45       last = row
46
47 if __name__ == "__main__":
48         def signal_handler(signal, frame):
49                 print('SIG received. exitting!')
50                 sys.exit(0)
51         signal.signal(signal.SIGINT, signal_handler)
52
53         bladecode("dump_selected_udp_single_src_port_dehexed.csv")
54