Skip to content

Code refactoring #3

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

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
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
52 changes: 18 additions & 34 deletions Scanner.py
Original file line number Diff line number Diff line change
@@ -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 -sU"),
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')
if resp in scan_types:
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(scanner[ip_addr].all_protocols())
print("Open Ports: ", scanner[ip_addr]['tcp'].keys())
elif resp >= '4':
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")