Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 17 additions & 12 deletions src/scanner.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#fixed some print errors and syntax errors
#!/usr/bin/env python
import socket
import subprocess
Expand All @@ -6,22 +7,26 @@
import json
import os
import threading
import __builtin__
import builtins
from multi.scanner_thread import split_processing

exc = getattr(__builtin__, "IOError", "FileNotFoundError")
exc = getattr(builtins, "IOError", "FileNotFoundError")

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

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


raw_input = input("Enter a remote host to scan: ")

remoteServer = raw_input
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 ("-")
print ("Please wait, scanning remote host...."), remoteServerIP
print ("-")

# Resolves the relative path to absolute path
# [BUG]: https://github.com/vinitshahdeo/PortScanner/issues/19
Expand All @@ -38,7 +43,7 @@ def get_absolute_path(relative_path):
try:
with open(get_absolute_path('../config.json')) as config_file:
config = json.load(config_file)
print get_absolute_path('../config.json')
print(f"{get_absolute_path}../config.json")
range_high = int(config['range']['high'])
range_low = int(config['range']['low'])
# defining number of threads running concurrently
Expand All @@ -58,19 +63,19 @@ def scan(ports, range_low, range_high):
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()


Expand All @@ -84,4 +89,4 @@ def scan(ports, range_low, range_high):
total = t2 - t1

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