Python nmap.PortScannerError() Examples
The following are 2
code examples of nmap.PortScannerError().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
nmap
, or try the search function
.
Example #1
Source File: action.py From insightconnect-plugins with MIT License | 5 votes |
def run(self, params={}): hosts_to_scan = params.get("hosts") ports_to_scan = params.get("ports") nmap_args = params.get("arguments") sudo = params.get("sudo") # defaulted to False if not len(ports_to_scan): ports_to_scan = None if not len(nmap_args): nmap_args = None scanner = PortScanner() try: scanner.scan(hosts=hosts_to_scan, ports=ports_to_scan, arguments=nmap_args, sudo=sudo) except PortScannerError as e: self.logger.error("An error occurred: %s" % e) else: scanned_hosts = scanner.all_hosts() # grab hosts that were scanned results = list(map(lambda host: scanner[host], scanned_hosts)) # create list of scan results results = komand.helper.clean(results) return {"result": results}
Example #2
Source File: nmap.py From w12scan-client with MIT License | 5 votes |
def nmapscan(host, ports): # 接受从masscan上扫描出来的结果 # 为了可以多线程使用,此函数支持多线程调用 nm = nmap.PortScanner() argument = "-sV -sS -Pn --host-timeout 1m -p{}".format(','.join(ports)) try: ret = nm.scan(host, arguments=argument) except nmap.PortScannerError: logger.debug("Nmap PortScannerError host:{}".format(host)) return None except: return None # debug elapsed = ret["nmap"]["scanstats"]["elapsed"] command_line = ret["nmap"]["command_line"] logger.debug("[nmap] successed,elapsed:%s command_line:%s" % (elapsed, command_line)) if host in ret["scan"]: try: result = ret["scan"][host]["tcp"] except KeyError: return None return result return None