Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/env python
- import socket
- import subprocess
- import sys
- from random import shuffle
- import time
- from datetime import datetime
- import geoip2.database
- import ipaddress
- # Clear the screen
- subprocess.call('clear', shell=True)
- # Database acquired from https://dev.maxmind.com/geoip/geoip2/geolite2/
- reader = geoip2.database.Reader('C:/Users/Notandi/Downloads/GeoLite2-Country_20180206/GeoLite2-Country.mmdb')
- # Our subnet´s are: 80.248.16.0/20: 80.248.16.0 - 80.248.31.255
- # and 82.148.64.0/19: 82.148.64.0 - 82.148.95.255
- # List of IP's to check
- net = ipaddress.ip_network('80.248.16.0/20')
- #net = ipaddress.ip_network('82.148.64.0/19')
- ipList = []
- # Populate the list with addresses
- for a in net:
- ipList.append(str(a))
- scanList = []
- shuffle(ipList)
- # Check if any of the provided IP's are from machines in Iceland.
- for i in range (0, len(ipList)):
- response = reader.country(ipList[i])
- if response.country.name == 'Iceland':
- scanList.append(ipList[i])
- print(ipList[i], ' is an Icelandic IP address.')
- else:
- print(ipList[i], ' is not an Icelandic IP address.')
- # Scan the Icelandic IP's using a predetermined list of likely ICS ports
- for i in range (0, len(scanList)):
- remoteServerIP = scanList[i]
- # Print a nice banner with information on which host we are about to scan
- print("-" * 60)
- print("Please wait, scanning remote host...", remoteServerIP)
- try:
- print("Host name: ", socket.gethostbyaddr(remoteServerIP))
- except socket.error:
- print("Host name could not be resolved.")
- print("-" * 60)
- # Check what time the scan started
- t1 = datetime.now()
- # A complete list of all the ports we found mentions of in our research
- portlist = [80,123,102,443,502,530,593,789,1089,1090,1091,1153,1911,
- 1962,2222,2404,4000,4840,4843,4911,5064,5065,5094,9600,
- 19999,20000,20547,34962,34963,34964,34980,40000,44818,
- 46823,46824,47808,55001,55002,55003,58372]
- openPorts = []
- shuffle(portlist)
- f = open('openports.txt', 'w')
- # Check the ports and write the open ones and their IP's to a simple .txt file.
- try:
- for i in range (0, len(portlist)):
- sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
- result = sock.connect_ex((remoteServerIP, portlist[i]))
- if result == 0:
- print("Port {}: Open".format(portlist[i]))
- openPort = str(remoteServerIP) + ':' + str(portlist[i])
- openPorts.append(openPort)
- f.write(openPort + '\n')
- else:
- print("Port {}: Closed".format(portlist[i]))
- sock.close()
- time.sleep(0.6)
- except KeyboardInterrupt:
- print("You pressed Ctrl+C. Scan aborted.")
- sys.exit()
- except socket.gaierror:
- print('Hostname could not be resolved. Exiting...')
- sys.exit()
- except socket.error:
- print("Couldn't connect to server. Exiting...")
- sys.exit()
- # Checking the time again
- t2 = datetime.now()
- # Calculates the difference of time, to see how long it took to run the scr$
- total = t2 - t1
- # Printing the information to screen
- print('Scanning Completed in: ', total)
- #print(openPorts)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement