本文整理汇总了Python中nmap.PortScannerError方法的典型用法代码示例。如果您正苦于以下问题:Python nmap.PortScannerError方法的具体用法?Python nmap.PortScannerError怎么用?Python nmap.PortScannerError使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类nmap
的用法示例。
在下文中一共展示了nmap.PortScannerError方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: run
# 需要导入模块: import nmap [as 别名]
# 或者: from nmap import PortScannerError [as 别名]
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}
示例2: nmapscan
# 需要导入模块: import nmap [as 别名]
# 或者: from nmap import PortScannerError [as 别名]
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