From dbf3a6bfe7f8ec0ef4619f74b9813d42c50e0612 Mon Sep 17 00:00:00 2001 From: Mike Cromwell Date: Sat, 26 Jan 2019 15:45:25 +0000 Subject: [PATCH 1/4] refatoring code --- Scanner.py | 54 +++++++++++++++++++----------------------------------- 1 file changed, 19 insertions(+), 35 deletions(-) diff --git a/Scanner.py b/Scanner.py index d174c55..b87a05f 100644 --- a/Scanner.py +++ b/Scanner.py @@ -1,50 +1,34 @@ #!/usr/bin/python3 - import nmap +import collections scanner = nmap.PortScanner() +ScanType = collections.namedtuple("ScanType", "proto args") +scan_types = { + 1: ScanType(proto="tcp", args="-v -sS"), + 2: ScanType(proto="udp", args="-v -sS"), + 3: ScanType(proto="tcp", args="-v -sS -sV -sC -A -O") +} print("Welcome, this is a simple nmap automation tool") -print("<----------------------------------------------------->") +print("<", ">", sep="-" * 45) 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 +resp = int(input("""\nPlease enter the type of scan you want to run 1)SYN ACK Scan 2)UDP Scan - 3)Comprehensive Scan \n""") + 3)Comprehensive Scan \n""")) print("You have selected option: ", resp) -if resp == '1': - print("Nmap Version: ", scanner.nmap_version()) - scanner.scan(ip_addr, '1-1024', '-v -sS') - print(scanner.scaninfo()) - print("Ip Status: ", scanner[ip_addr].state()) - print(scanner[ip_addr].all_protocols()) - print("Open Ports: ", scanner[ip_addr]['tcp'].keys()) -elif resp == '2': - print("Nmap Version: ", scanner.nmap_version()) - scanner.scan(ip_addr, '1-1024', '-v -sU') - print(scanner.scaninfo()) - print("Ip Status: ", scanner[ip_addr].state()) - print(scanner[ip_addr].all_protocols()) - print("Open Ports: ", scanner[ip_addr]['udp'].keys()) -elif resp == '3': - print("Nmap Version: ", scanner.nmap_version()) - scanner.scan(ip_addr, '1-1024', '-v -sS -sV -sC -A -O') - print(scanner.scaninfo()) - print("Ip Status: ", scanner[ip_addr].state()) - print(scanner[ip_addr].all_protocols()) - print("Open Ports: ", scanner[ip_addr]['tcp'].keys()) -elif resp >= '4': +if resp not in scan_types: print("Please enter a valid option") - - - - - - - - +else: + scan_type = scan_types[resp] + "Nmap Version: ", scanner.nmap_version() + scanner.scan(ip_addr, '1-1024', scan_type.args) + print(scanner.scaninfo()) + print("IP Status: ", scanner[ip_addr].state()) + print("Protocols: ", ", ".join(scanner[ip_addr].all_protocols())) + print("Open Ports: ", ", ".join(str(p) for p in scanner[ip_addr][scan_type.proto].keys())) From 36302b5faa2291495e5150f7119e08a69782ebed Mon Sep 17 00:00:00 2001 From: Mike Cromwell Date: Sat, 26 Jan 2019 15:50:58 +0000 Subject: [PATCH 2/4] reversing logic --- Scanner.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Scanner.py b/Scanner.py index b87a05f..fc4953e 100644 --- a/Scanner.py +++ b/Scanner.py @@ -22,9 +22,7 @@ 3)Comprehensive Scan \n""")) print("You have selected option: ", resp) -if resp not in scan_types: - print("Please enter a valid option") -else: +if resp in scan_types: scan_type = scan_types[resp] "Nmap Version: ", scanner.nmap_version() scanner.scan(ip_addr, '1-1024', scan_type.args) @@ -32,3 +30,5 @@ print("IP Status: ", scanner[ip_addr].state()) print("Protocols: ", ", ".join(scanner[ip_addr].all_protocols())) print("Open Ports: ", ", ".join(str(p) for p in scanner[ip_addr][scan_type.proto].keys())) +else: + print("Please enter a valid option") \ No newline at end of file From 320cf6d096a5cfa02f7a8496f2d2deca13d7452d Mon Sep 17 00:00:00 2001 From: Mike Cromwell Date: Sat, 26 Jan 2019 15:56:17 +0000 Subject: [PATCH 3/4] fixing udp --- Scanner.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Scanner.py b/Scanner.py index fc4953e..248e5c4 100644 --- a/Scanner.py +++ b/Scanner.py @@ -6,7 +6,7 @@ ScanType = collections.namedtuple("ScanType", "proto args") scan_types = { 1: ScanType(proto="tcp", args="-v -sS"), - 2: ScanType(proto="udp", args="-v -sS"), + 2: ScanType(proto="udp", args="-v -sU"), 3: ScanType(proto="tcp", args="-v -sS -sV -sC -A -O") } From bfc12ce6b6cf9d8072486bf5e9eac45d2decb209 Mon Sep 17 00:00:00 2001 From: Mike Date: Sat, 26 Jan 2019 16:00:51 +0000 Subject: [PATCH 4/4] Update Scanner.py --- Scanner.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Scanner.py b/Scanner.py index 248e5c4..8936b1e 100644 --- a/Scanner.py +++ b/Scanner.py @@ -31,4 +31,4 @@ print("Protocols: ", ", ".join(scanner[ip_addr].all_protocols())) print("Open Ports: ", ", ".join(str(p) for p in scanner[ip_addr][scan_type.proto].keys())) else: - print("Please enter a valid option") \ No newline at end of file + print("Please enter a valid option")