本文整理汇总了Python中libnmap.process.NmapProcess.sudo_run_background方法的典型用法代码示例。如果您正苦于以下问题:Python NmapProcess.sudo_run_background方法的具体用法?Python NmapProcess.sudo_run_background怎么用?Python NmapProcess.sudo_run_background使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类libnmap.process.NmapProcess
的用法示例。
在下文中一共展示了NmapProcess.sudo_run_background方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: nmap_scan
# 需要导入模块: from libnmap.process import NmapProcess [as 别名]
# 或者: from libnmap.process.NmapProcess import sudo_run_background [as 别名]
def nmap_scan(hosts):
'''
Do Nmap scan
'''
# -sV is included by default in NmapProcess nmap cmd
# To add more: options = '-T4 -sU -p-'
# hosts = ['192.168.0.1', '192.168.0.2']
#nmap_args = '-T4 -sV -sS -pU:161,137,139'# -sS -sU --top-ports'
nmap_args = '-T4 -sS -sV --max-rtt-timeout 150ms --max-retries 3'
print '[*] Running: nmap {0} -iL <hostlist>'.format(nmap_args)
nmap_proc = NmapProcess(targets=hosts, options=nmap_args)
#rc = nmap_proc.sudo_run()
rc = nmap_proc.sudo_run_background()
while nmap_proc.is_running():
print("[*] Nmap progress: {1}%".format(nmap_proc.etc, nmap_proc.progress))
time.sleep(2)
xml = nmap_proc.stdout
try:
report = NmapParser.parse(nmap_proc.stdout)
except NmapParserException as e:
print 'Exception raised while parsing scan: {0}'.format(e.msg)
sys.exit()
return report
示例2: perform_scan
# 需要导入模块: from libnmap.process import NmapProcess [as 别名]
# 或者: from libnmap.process.NmapProcess import sudo_run_background [as 别名]
def perform_scan(config_file, section, targets, output_dir):
# merge targets to create the smallest possible list of CIDR subnets
subnets = list()
for target in targets:
subnets.append(IPNetwork(target))
subnets = cidr_merge(subnets)
targets = list()
for subnet in subnets:
targets.append(str(subnet))
# check if required args declaration is supplied
config = ConfigParser.ConfigParser()
config.read(config_file)
args = config_section_map(config, section)['args']
if not args:
error('No \'args\' declaration found in %s' % section)
exit()
# check for options that will interfere with this script
illegal_options = ['-oG', '-oN', '-iL', '-oA', '-oS', '-oX', '--iflist',
'--resume', '--stylesheet', '--datadir', '--stats-every']
for option in illegal_options:
if option in args:
error('\'args\' declaration contains incompatible option \'%s\'' %
(section, option))
exit()
# store raw nmap output as well
raw_file = '%s/%s.nmap' % (output_dir, section)
args += ' -oN %s' % raw_file
# perform scan
info('Starting scan \'%s\'' % section)
print(' -> %s' % config_section_map(config, section)['desc'])
nmap_proc = NmapProcess(targets=targets, options=args, safe_mode=False)
nmap_proc.sudo_run_background()
while nmap_proc.is_running():
nmap_task = nmap_proc.current_task
if nmap_task:
m, s = divmod(int(nmap_task.remaining), 60)
h, m = divmod(m, 60)
remaining = "%d:%02d:%02d" % (h, m, s)
sys.stdout.write(
'[+] Task: {0} - ETC: {1} DONE: {2}%'
' \r'.format(
nmap_task.name,
remaining,
nmap_task.progress))
sys.stdout.flush()
sleep(1)
# save results
if nmap_proc.rc == 0:
info('%s' % nmap_proc.summary.replace('Nmap done at',
'Scan completed on'))
run('chown %s:%s %s' % (os.getuid(), os.getgid(), raw_file), sudo=True)
print(" -> Nmap report saved to '%s'" % raw_file)
if nmap_proc.stdout:
xml_file = '%s/%s.xml' % (output_dir, section)
out = open(xml_file, 'w')
out.write(nmap_proc.stdout)
out.close()
print(" -> XML report saved to '%s'" % xml_file)
#if nmap_proc.stderr:
# err_file = '%s/%s.err' % (output_dir, section)
# out = open(err_file, 'w')
# out.write(nmap_proc.stderr)
# out.close()
# print(" -> Standard error output saved to '%s'" %
# err_file)
else:
error('Error occurred:')
print(' -> %s' % nmap_proc.stderr.rstrip())