要扫描文件,但遇到错误。 仅>>
已启动NMap扫描
它没有扫描
我尝试了pip install python-nmap 并且还安装了pip install nmap
import nmap
#from common import CommonLibrary
#from scanconfig import ScanConfiguration
import json
from predsac.common import CommonLibrary
class NMapScanner:
def __init__(self):
"""initialize the port scanner"""
self.nmScan = nmap.PortScanner()
# scan_configuration = ScanConfiguration()
self.ports = '0-10'# scan_configuration.get_config('NMAP', 'PORT_RANGE') TODO
def perform_nmap_scan_with_hosts_ports_arguments(self, hosts, ports, arguments):
"""initiate scan based on the host, ports and commands"""
return self.nmScan.scan(hosts=hosts, ports=ports, arguments=arguments,sudo=True)
def init_nmap_scan(self, ip_address, app_identifier, created_on):
print("NMap scan initiated")
common = CommonLibrary()
# scan_result_path = common.get_scan_result_path(app_identifier, created_on, 'nmap')
scan_result_path = '/home/predsac/Project/New/TestFolder'
"""
result = '['
flag = True
for scan in settings.NMAP_SETTINGS["SCANS"]: # Second Example
if flag is False:
result = result + ','
result = result + str(self.perform_nmap_scan_with_hosts_ports_arguments(ip_address, ports, scan))
flag = False
print(scan + " scan completed")
result = result + ']'
common.write_to_file("nmap_result", result, scan_result_path)
"""
# TCP Connect Scan: nmap -sT -p0-65535 <IP>
tcp_connect = self.perform_nmap_scan_with_hosts_ports_arguments(ip_address, self.ports, "-sT")
common.write_to_file("TCP Connect.json", tcp_connect, scan_result_path)
print("TCP connect scan completed")
# TCP SYN Scan: nmap -sS -p0-65535 <IP>
tcp_syn = self.perform_nmap_scan_with_hosts_ports_arguments(ip_address, self.ports, "-sS")
common.write_to_file("TCP SYN.json", tcp_syn, scan_result_path)
print("TCP SYN scan completed")
# UDP Discovery: nmap -sU -p0-65535 <IP>
udp_discovery = self.perform_nmap_scan_with_hosts_ports_arguments(ip_address, self.ports, "-sU")
common.write_to_file("UDP Discovery.json", udp_discovery, scan_result_path)
print("UDP discovery scan completed")
# Fingerprint Scan: nmap -sV -p0-65535 <IP>
finger_print = self.perform_nmap_scan_with_hosts_ports_arguments(ip_address, self.ports, "-sV")
common.write_to_file("Fingerprint.json", finger_print, scan_result_path)
print("Fingerprint scan completed")
# Vulnerability Check: nmap -sC -p0-65535 <IP>
vulnerability = self.perform_nmap_scan_with_hosts_ports_arguments(ip_address, self.ports, "-sC")
common.write_to_file("Vulnerability.json", vulnerability, scan_result_path)
print("Vulnerability scan completed")
combined_scan_result = {
"tcp_connect": tcp_connect,
"tcp_syn": tcp_syn,
"udp_discovery": udp_discovery,
"finger_print": finger_print,
"vulnerability": vulnerability,
}
common.write_to_file("nmap_html_result.html", common.make_html(combined_scan_result, 'NMap Results'),
scan_result_path)
print("NMap scan completed")
在调试中仅进行
>
已启动NMap扫描