Source Code for network and port scanner, TRW algorithm, and reduction method implementations.

erase2.py 853B

12345678910111213141516171819202122232425262728293031
  1. import json
  2. PATH = '../../netflows.txt'
  3. myFile = open(PATH, 'r')
  4. ip = myFile.read()
  5. flow = json.loads(ip)
  6. dportHash = {}
  7. otherHash = {}
  8. for i in flow["flows"]:
  9. sip = i['sip']
  10. dip = i['dip']
  11. dport = i['dport']
  12. if sip in dportHash:
  13. if dip in dportHash[sip]:
  14. dportHash[sip][dip].append(dport)
  15. else:
  16. dportHash[sip][dip] = [dport]
  17. else:
  18. dportHash[sip] = { dip: [dport] }
  19. print dportHash
  20. for sips in dportHash: #se itera por todos los dip y sus counters o puertos
  21. for dips, dports in dportHash[sips].items():
  22. print sips, dips, dports
  23. print len(dports)
  24. if sips in otherHash:
  25. otherHash[sips][dips] = dports
  26. print "OtherHash", otherHash[sips][dips]
  27. else:
  28. otherHash[sips] = {dips: dports}