1234567891011121314151617181920212223242526272829303132333435363738 |
- import json
-
- PATH = '../../netflows.txt'
-
- myFile = open(PATH, 'r')
- ip = myFile.read()
- print type(ip)
- flow = json.loads(ip)
- dportHash = {}
- otherHash = {}
- for i in flow["flows"]:
- sip = i['sip']
- dip = i['dip']
- dport = i['dport']
- if sip in dportHash:
- if dip in dportHash[sip]:
- if dport in dportHash[sip][dip]:
- dportHash[sip][dip][dport] += 1
- else:
- dportHash[sip][dip][dport] = 1
- else:
- dportHash[sip][dip] = {dport : 1}
- else:
- dportHash[sip] = { dip: {dport: 1} }
- print dportHash
-
-
- for sips in dportHash: #se itera por todos los dip y sus counters o puertos
- for dips, dports in dportHash[sips].items():
- print sips, dips, dports
- print len(dports)
- if sips in otherHash:
- otherHash[sips][dips] = dports
- print "OtherHash", otherHash
- else:
- hash = {dips: dports}
- print hash
- otherHash[sips] = {dips: dports}
|