-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathnmap_scan.py
More file actions
28 lines (20 loc) · 919 Bytes
/
nmap_scan.py
File metadata and controls
28 lines (20 loc) · 919 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
27
28
import nmap
target = input("Enter the target IP address or hostname: ")
# Create a PortScanner object
scanner = nmap.PortScanner()
# Define the arguments for the scan
arguments = '-p- -sV -O -T4'
# Scan the target with the specified arguments
result = scanner.scan(target, arguments=arguments)
# Retrieve the OS information
os = result['scan'][target]['osmatch'][0]['name']
# Get the total number of open ports
open_ports = [port for port in scanner[target]['tcp'] if scanner[target]['tcp'][port]['state'] == 'open']
# Iterate over the scanned ports and retrieve service information
for port in open_ports:
state = scanner[target]['tcp'][port]['state']
service = scanner[target]['tcp'][port]['name']
version = scanner[target]['tcp'][port]['version']
if state == 'open':
print("Port {} is open. Service: {} Version: {} OS: {}".format(port, service, version, os))
print("Scan completed!")