Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Migration to python3.8+ #143

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
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
12 changes: 6 additions & 6 deletions src/ipscanner.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,15 @@
from multi.scanner_thread import split_processing

# Ask for input
net1 = raw_input('Enter the IP address: ')
net1 = input('Enter the IP address: ')
net2 = net1.split('.')
a = '.'
net3 = net2[0] + a + net2[1] + a + net2[2] + a

# Print a nice banner with information on which host we are about to scan
print "-" * 60
print "Please wait, scanning IP address....", net3+"XXX"
print "-" * 60
print ("-" * 60)
print ("Please wait, scanning IP address....", net3+"XXX")
print ("-" * 60)

# Resolves the relative path to absolute path
# [BUG]: https://github.com/vinitshahdeo/PortScanner/issues/19
Expand Down Expand Up @@ -67,7 +67,7 @@ def run1(ips, range_low, range_high):
addr = net3+str(ip)
# gets full address
if (scan(addr)):
print addr + " is live\n"
print (addr + " is live\n")


# calling function from scanner_thread.py for multithreading
Expand All @@ -77,4 +77,4 @@ def run1(ips, range_low, range_high):
# Calculates the difference of time, to see how long it took to run the script
total = td2-td1
# Printing the information to screen
print "Scanning completed in ", total
print ("Scanning completed in ", total)
24 changes: 12 additions & 12 deletions src/mainScanner.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
#!/usr/bin/env python
#!/usr/bin/env python3
import socket
import subprocess
import sys
from datetime import datetime
import json
import os
import threading
import __builtin__
import builtins
from multi.scanner_thread import split_processing
import logging
from flask import Flask, render_template, request, redirect, url_for
Expand All @@ -19,7 +19,7 @@ def homepage():
return render_template('index.html')


exc = getattr(__builtin__, "IOError", "FileNotFoundError")
exc = getattr(__builtins__, "IOError", "FileNotFoundError")
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure if this line would not throw error while running.
It should be
exc = getattr(builtins, "IOError", "FileNotFoundError")
instead of
exc = getattr(__builtins__, "IOError", "FileNotFoundError"),
I suppose.

Reference.

@ranaaditya does this file execute normally with __builtins__ ?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, it was working fine in my local.


# Clear the screen
# subprocess.call('clear', shell=True)
Expand All @@ -37,9 +37,9 @@ def input():
return EnvironmentError

# 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)

# Resolves the relative path to absolute path
# [BUG]: https://github.com/vinitshahdeo/PortScanner/issues/19
Expand All @@ -56,7 +56,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 (get_absolute_path('../config.json'))
# defining number of threads running concurrently
CONST_NUM_THREADS = int(config['thread']['count'])

Expand All @@ -76,20 +76,20 @@ 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))
portnum.append("Port "+str(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()

# calling function from scanner_thread.py for multithreading
Expand All @@ -102,7 +102,7 @@ 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)
return render_template('index.html', portnum=portnum, host=remoteServerIP, range_low=range_low, range_high=range_high, total=total)


Expand Down
26 changes: 13 additions & 13 deletions src/scanner.py
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,27 +1,27 @@
#!/usr/bin/env python
#!/usr/bin/env python3
import socket
import subprocess
import sys
from datetime import datetime
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: ")
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)

# Resolves the relative path to absolute path
# [BUG]: https://github.com/vinitshahdeo/PortScanner/issues/19
Expand All @@ -38,7 +38,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( 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 +58,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 +84,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)
20 changes: 10 additions & 10 deletions src/single/scanner.py
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/usr/bin/env python
#!/usr/bin/env python3
import socket
import subprocess
import sys
Expand All @@ -8,13 +8,13 @@
subprocess.call('clear', shell=True)

# 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()
Expand All @@ -26,19 +26,19 @@
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 +48,4 @@
total = t2 - t1

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