-
Notifications
You must be signed in to change notification settings - Fork 0
/
nmap_scan.py
26 lines (22 loc) · 862 Bytes
/
nmap_scan.py
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
def scan_target(target):
nm = nmap.PortScanner()
nm.scan(target, arguments='-p- -sV')
return nm
def display_results(nm):
for host in nm.all_hosts():
print(f"\nHost: {host} ({nm[host].hostname()})")
print(f"State: {nm[host].state()}")
for proto in nm[host].all_protocols():
print(f"\nProtocol: {proto}")
for port in sorted(nm[host][proto].keys()):
state = nm[host][proto][port]['state']
service = nm[host][proto][port]['name']
version = nm[host][proto][port].get('version', 'N/A')
print(f"Port: {port}\tState: {state}\tService: {service}\tVersion: {version}")
def main():
target = input("Enter the target IP or hostname: ")
nm = scan_target(target)
display_results(nm)
if __name__ == "__main__":
main()