-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscanner_advance.py
30 lines (26 loc) · 943 Bytes
/
scanner_advance.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
27
28
29
30
# scanner_advance.py
import nmap
def scan_target(ip_address):
nm = nmap.PortScanner()
nm.scan(ip_address, arguments='-sCV')
service_data = []
if ip_address in nm.all_hosts():
for proto in nm[ip_address].all_protocols():
lport = nm[ip_address][proto].keys()
for port in lport:
service_info = {
'port': port,
'name': nm[ip_address][proto][port]['name'],
'version': nm[ip_address][proto][port]['version'],
'state': nm[ip_address][proto][port]['state'],
}
service_data.append(service_info)
return service_data
else:
return None
def get_open_ports(service_data):
open_ports = []
for service in service_data:
if service['state'] == 'open':
open_ports.append(service['port'])
return ','.join(map(str, open_ports))