12345678910111213141516171819202122232425262728293031 |
- import json
-
- PATH = '../../netflows.txt'
- myFile = open(PATH, 'r')
- ip = myFile.read()
- 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]:
- dportHash[sip][dip].append(dport)
- else:
- dportHash[sip][dip] = [dport]
- else:
- dportHash[sip] = { dip: [dport] }
-
- 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[sips][dips]
- else:
- otherHash[sips] = {dips: dports}
|