Advertisement
Guest User

Untitled

a guest
Feb 22nd, 2018
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.35 KB | None | 0 0
  1. #!/usr/bin/env python
  2. import socket
  3. import subprocess
  4. import sys
  5. from random import shuffle
  6. import time
  7. from datetime import datetime
  8. import geoip2.database
  9. import ipaddress
  10.  
  11. # Clear the screen
  12. subprocess.call('clear', shell=True)
  13.  
  14. # Database acquired from https://dev.maxmind.com/geoip/geoip2/geolite2/
  15. reader = geoip2.database.Reader('C:/Users/Notandi/Downloads/GeoLite2-Country_20180206/GeoLite2-Country.mmdb')
  16.  
  17. # Our subnet´s are: 80.248.16.0/20: 80.248.16.0 - 80.248.31.255
  18. # and 82.148.64.0/19: 82.148.64.0 - 82.148.95.255
  19.  
  20. # List of IP's to check
  21. net = ipaddress.ip_network('80.248.16.0/20')
  22. #net = ipaddress.ip_network('82.148.64.0/19')
  23.  
  24. ipList = []
  25. # Populate the list with addresses
  26. for a in net:
  27. ipList.append(str(a))
  28.  
  29. scanList = []
  30. shuffle(ipList)
  31.  
  32. # Check if any of the provided IP's are from machines in Iceland.
  33. for i in range (0, len(ipList)):
  34. response = reader.country(ipList[i])
  35. if response.country.name == 'Iceland':
  36. scanList.append(ipList[i])
  37. print(ipList[i], ' is an Icelandic IP address.')
  38. else:
  39. print(ipList[i], ' is not an Icelandic IP address.')
  40.  
  41. # Scan the Icelandic IP's using a predetermined list of likely ICS ports
  42. for i in range (0, len(scanList)):
  43. remoteServerIP = scanList[i]
  44.  
  45. # Print a nice banner with information on which host we are about to scan
  46. print("-" * 60)
  47. print("Please wait, scanning remote host...", remoteServerIP)
  48. try:
  49. print("Host name: ", socket.gethostbyaddr(remoteServerIP))
  50. except socket.error:
  51. print("Host name could not be resolved.")
  52. print("-" * 60)
  53.  
  54. # Check what time the scan started
  55. t1 = datetime.now()
  56.  
  57. # A complete list of all the ports we found mentions of in our research
  58. portlist = [80,123,102,443,502,530,593,789,1089,1090,1091,1153,1911,
  59. 1962,2222,2404,4000,4840,4843,4911,5064,5065,5094,9600,
  60. 19999,20000,20547,34962,34963,34964,34980,40000,44818,
  61. 46823,46824,47808,55001,55002,55003,58372]
  62. openPorts = []
  63. shuffle(portlist)
  64. f = open('openports.txt', 'w')
  65.  
  66. # Check the ports and write the open ones and their IP's to a simple .txt file.
  67. try:
  68. for i in range (0, len(portlist)):
  69. sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
  70. result = sock.connect_ex((remoteServerIP, portlist[i]))
  71. if result == 0:
  72. print("Port {}: Open".format(portlist[i]))
  73. openPort = str(remoteServerIP) + ':' + str(portlist[i])
  74. openPorts.append(openPort)
  75. f.write(openPort + '\n')
  76. else:
  77. print("Port {}: Closed".format(portlist[i]))
  78. sock.close()
  79. time.sleep(0.6)
  80.  
  81. except KeyboardInterrupt:
  82. print("You pressed Ctrl+C. Scan aborted.")
  83. sys.exit()
  84.  
  85. except socket.gaierror:
  86. print('Hostname could not be resolved. Exiting...')
  87. sys.exit()
  88.  
  89. except socket.error:
  90. print("Couldn't connect to server. Exiting...")
  91. sys.exit()
  92.  
  93. # Checking the time again
  94. t2 = datetime.now()
  95.  
  96. # Calculates the difference of time, to see how long it took to run the scr$
  97. total = t2 - t1
  98.  
  99. # Printing the information to screen
  100. print('Scanning Completed in: ', total)
  101. #print(openPorts)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement