From 4b61fda7e6c24416f796a7674759ffaecba247c1 Mon Sep 17 00:00:00 2001 From: Kaikane Anderson <109874492+Kvikvne@users.noreply.github.com> Date: Wed, 31 Jan 2024 19:42:54 -0800 Subject: [PATCH] Updated port scanner --- Scanner.py | 63 ++++++++++++++++++++++++++++++++++-------------------- 1 file changed, 40 insertions(+), 23 deletions(-) diff --git a/Scanner.py b/Scanner.py index 9bf42ba..46b3e2f 100644 --- a/Scanner.py +++ b/Scanner.py @@ -4,29 +4,46 @@ scanner = nmap.PortScanner() -print("Welcome, this is a simple nmap automation tool") -print("<----------------------------------------------------->") - -ip_addr = input("Please enter the IP address you want to scan: ") -print("The IP you entered is: ", ip_addr) -type(ip_addr) - -resp = input("""\nPlease enter the type of scan you want to run - 1)SYN ACK Scan - 2)UDP Scan - 3)Comprehensive Scan \n""") -print("You have selected option: ", resp) -resp_dict={'1':['-v -sS','tcp'],'2':['-v -sU','udp'],'3':['-v -sS -sV -sC -A -O','tcp']} -if resp not in resp_dict.keys(): - print("enter a valid option") -else: - print("nmap version: "sccaner.nmap_version()) - scanner.scan(ip_addr,"1-1024",resp_dict[resp][0]) #the # are port range to scan, the last part is the scan type - print(scanner.scaninfo()) - if scanner.scaninfo()=='up': - print("Scanner Status: ",scanner[ip_addr].state()) - print(scanner[ip_addr].all_protocols()) - print("Open Ports: ",scanner[ip_addr][resp_dict[resp][1]].keys()) #display all open ports +print("Welcome, this is a simple nmap automation tool.") +print("-------------------------------------------------") + +ip_addr = input("IP: ") +print("The IP you entered is:", ip_addr) + +while True: + resp = input( + """\nEnter the type of scan you want to run + 1) SYN ACK Scan + 2) UDP Scan + 3) Comprehensive Scan + """ + ) + print("You have selected option:", resp) + + if resp in {'1', '2', '3'}: + options = '-v' + if resp == '3': + options += ' -sV -sC -A -O' + + if resp == '1': + scanner.scan(ip_addr, '1-1024', f'{options} -sS') + protocol = 'TCP' + elif resp == '2': + scanner.scan(ip_addr, '1-1024', f'{options} -sU') + protocol = 'UDP' + else: + scanner.scan(ip_addr, '1-1024', f'{options} -sS') + protocol = 'TCP' + + print("Nmap Version:", '.'.join(map(str, scanner.nmap_version()))) + print("Scan Info:", scanner.scaninfo()) + print("IP Status:", scanner[ip_addr].state()) + print("Protocol:", protocol) + print("Open ports:", list(scanner[ip_addr][protocol.lower()].keys())) + break + else: + print("Invalid option") +