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

erase.py 1.0KB

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