-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathport_scanner.py
More file actions
26 lines (20 loc) · 895 Bytes
/
port_scanner.py
File metadata and controls
26 lines (20 loc) · 895 Bytes
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
import nmap
# User input
target_ip = input("Enter target IP address: ")
# Create scanner object
scanner = nmap.PortScanner()
print(f"[*] Scanning target: {target_ip} ...")
scanner.scan(target_ip, arguments="-sS -sV -T4")
# Loop through results
for host in scanner.all_hosts():
print(f"\nHost: {host} ({scanner[host].hostname()})")
print(f"State: {scanner[host].state()}")
for proto in scanner[host].all_protocols():
print(f"\nProtocol: {proto}")
ports = scanner[host][proto].keys()
for port in sorted(ports):
state = scanner[host][proto][port]['state']
name = scanner[host][proto][port]['name']
product = scanner[host][proto][port].get('product', '')
version = scanner[host][proto][port].get('version', '')
print(f"Port: {port}\tState: {state}\tService: {name}\tVersion: {product} {version}")