本文整理汇总了Python中libnmap.process.NmapProcess.sudo_run方法的典型用法代码示例。如果您正苦于以下问题:Python NmapProcess.sudo_run方法的具体用法?Python NmapProcess.sudo_run怎么用?Python NmapProcess.sudo_run使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类libnmap.process.NmapProcess
的用法示例。
在下文中一共展示了NmapProcess.sudo_run方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: celery_nmap_scan
# 需要导入模块: from libnmap.process import NmapProcess [as 别名]
# 或者: from libnmap.process.NmapProcess import sudo_run [as 别名]
def celery_nmap_scan(targets, options):
"""celery_nmap_scan task"""
def status_callback(nmapscan=None):
"""status callback"""
try:
celery_nmap_scan.update_state(state="PROGRESS",
meta={"progress": nmapscan.progress,
"ready": 0,
"etc": nmapscan.etc})
except Exception as e:
print("status_callback error: " + str(e))
# scan is not yet finished (or even started).
# But I need to do this before the NmapProcess is started because
# otherwise other tasks might be queued in front of this!
_nmap_task_id = celery_nmap_scan.request.id
store_nmap_report_meta.apply_async(kwargs={'nmap_task_id': str(_nmap_task_id)})
print("tasks.py: Targets and Options")
print(targets)
print(options)
nm = NmapProcess(targets, options, event_callback=status_callback)
rc = nm.sudo_run()
if rc == 0 and nm.stdout:
r = nm.stdout
else:
r = None
return r
示例2: ip_info
# 需要导入模块: from libnmap.process import NmapProcess [as 别名]
# 或者: from libnmap.process.NmapProcess import sudo_run [as 别名]
def ip_info(subnet):
nm = NmapProcess(subnet, options="-Pn -O")
rc = nm.sudo_run()
if nm.rc == 0:
rep = NmapParser.parse(nm.stdout)
for host in rep.hosts:
if host.is_up():
print("IP Address: {0}".format(host.address))
if host.os_fingerprinted:
for osm in host.os.osmatches:
print("OS Type: {0}".format(osm.name))
print ("Last seen timestamp: {0}\n" .format(host.lastboot))
else:
print (nm.stderr)