Skip to content

Commit

Permalink
Merge pull request #4 from tinovasq/master
Browse files Browse the repository at this point in the history
Solves issue #1 and modernizes for Python 3.8
  • Loading branch information
vinitshahdeo committed Jun 12, 2020
2 parents 4b810af + 1fc0aed commit 4a7c895
Showing 1 changed file with 19 additions and 11 deletions.
30 changes: 19 additions & 11 deletions scanner.py
Expand Up @@ -3,42 +3,50 @@
import subprocess
import sys
from datetime import datetime
import json

# Clear the screen
subprocess.call('clear', shell=True)

# Pull port range from config.json
with open("config.json") as json_file:
data = json.load(json_file)
loRange = int(data['range']['low'])
hiRange = int(data['range']['high'])


# Ask for input
remoteServer = raw_input("Enter a remote host to scan: ")
remoteServer = input("Enter a remote host to scan: ")
remoteServerIP = socket.gethostbyname(remoteServer)

# Print a nice banner with information on which host we are about to scan
print "-" * 60
print "Please wait, scanning remote host....", remoteServerIP
print "-" * 60
print ("-" * 60)
print ("Please wait, scanning remote host....", remoteServerIP)
print ("-" * 60)

# Check what time the scan started
t1 = datetime.now()

# scanning the port only in range of (1, 8888)
# scanning the port in range specified in config.json

try:
for port in range(1,8888):
for port in range(loRange,hiRange):
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
result = sock.connect_ex((remoteServerIP, port))
if result == 0:
print "Port {}: Open".format(port)
print("Port {}: Open".format(port))
sock.close()

except KeyboardInterrupt:
print "You pressed Ctrl+C"
print("You pressed Ctrl+C")
sys.exit()

except socket.gaierror:
print 'Hostname could not be resolved. Exiting'
print ("Hostname could not be resolved. Exiting")
sys.exit()

except socket.error:
print "Couldn't connect to server"
print ("Couldn't connect to server")
sys.exit()

# Checking the time again
Expand All @@ -48,4 +56,4 @@
total = t2 - t1

# Printing the information to screen
print 'Scanning Completed in: ', total
print ('Scanning Completed in: ', total)

0 comments on commit 4a7c895

Please sign in to comment.