-
Notifications
You must be signed in to change notification settings - Fork 83
Expand file tree
/
Copy pathScanner.py
More file actions
55 lines (45 loc) · 1.64 KB
/
Copy pathScanner.py
File metadata and controls
55 lines (45 loc) · 1.64 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
#!/usr/bin/python3
import nmap
# Initialize the Nmap PortScanner
scanner = nmap.PortScanner()
print("Welcome, this is a simple Nmap automation tool")
print("<----------------------------------------------------->")
# 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:
# 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.")