本文整理匯總了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