Skip to content

Update Scanner.py #18

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 1 commit 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
73 changes: 46 additions & 27 deletions Scanner.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,35 +2,54 @@

import nmap

# Initialize the Nmap PortScanner
scanner = nmap.PortScanner()

print("Welcome, this is a simple nmap automation tool")
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")
# Input for target IP address
ip_addr = input("Please enter the IP address you want to scan: ").strip()
print(f"The IP you entered is: {ip_addr}")

# Scan type options
resp = input(
"""\nPlease enter the type of scan you want to run:
1) SYN ACK Scan
2) UDP Scan
3) Comprehensive Scan
Your choice: """
).strip()

# Mapping user response to Nmap commands and protocols
resp_dict = {
'1': ['-v -sS', 'tcp'], # SYN Scan
'2': ['-v -sU', 'udp'], # UDP Scan
'3': ['-v -sS -sV -sC -A -O', 'tcp'] # Comprehensive Scan
}

# Validate user input
if resp not in resp_dict:
print("Invalid option selected. Please choose 1, 2, or 3.")
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







# Display Nmap version
print(f"Nmap Version: {scanner.nmap_version()}")

# Execute the selected scan
print("\nScanning in progress...")
scanner.scan(ip_addr, "1-1024", resp_dict[resp][0]) # Scan ports 1-1024

# Display scan results
print("\nScan Info:", scanner.scaninfo())
if 'up' in scanner[ip_addr].state():
print(f"Scanner Status: {scanner[ip_addr].state()}")
print(f"Protocols: {scanner[ip_addr].all_protocols()}")

# Display open ports
protocol = resp_dict[resp][1]
if protocol in scanner[ip_addr]:
print(f"Open Ports ({protocol}): {list(scanner[ip_addr][protocol].keys())}")
else:
print(f"No open {protocol} ports found.")
else:
print("The host is down or unresponsive.")