From 2f26bfcf859a0b1584a346e7f208c6f199f27fbd Mon Sep 17 00:00:00 2001 From: David Morton Date: Thu, 21 Jul 2022 15:34:28 -0500 Subject: [PATCH] Create Portscan.py --- Portscan.py | 45 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) create mode 100644 Portscan.py diff --git a/Portscan.py b/Portscan.py new file mode 100644 index 0000000..3370dff --- /dev/null +++ b/Portscan.py @@ -0,0 +1,45 @@ +import socket +import sys + +def scanner(target, port): + #Banner Time + print("-" * 50) + print("Scanning: "+target) + print("Port Number: "+port) + print("-" * 50) + + try: + s=socket.socket(socket.AF_INET, socket.SOCK_STREAM) + socket.setdefaulttimeout(1) + result = s.connect_ex((target, port)) + if result == 0: + print("Port {port} is open.") + s.close() + except KeyboardInterrupt: + print("Closing Program") + sys.exit() + +def main(): + f=0 + while f==0: + try: + if sys.argv == 3: + target = socket.gethostbyname(sys.argv[1]) + port = sys.arg[2] + else: + print("Error Incorrect Syntax.\n Expected portscan.py ") + + while i != 1: + if port not in range(1,65535): + port = input("Please enter a valid port:\n") + else: + i = 1 + + scanner(target, port) + f=1 + except KeyboardInterrupt: + print("Closing Program") + sys.exit() + + except socket.gaierror: + target = input("Please enter a valid IP or Hostname:\n") \ No newline at end of file