当前位置: 首页>>代码示例>>Python>>正文


Python NmapProcess.stop方法代码示例

本文整理汇总了Python中libnmap.process.NmapProcess.stop方法的典型用法代码示例。如果您正苦于以下问题:Python NmapProcess.stop方法的具体用法?Python NmapProcess.stop怎么用?Python NmapProcess.stop使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在libnmap.process.NmapProcess的用法示例。


在下文中一共展示了NmapProcess.stop方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: run_nmap_scan

# 需要导入模块: from libnmap.process import NmapProcess [as 别名]
# 或者: from libnmap.process.NmapProcess import stop [as 别名]
def run_nmap_scan(scan_targets, scan_options):
    '''
    Accepts scan targets and scan options for NmapProcess and launches scan
    Prints scan status updates and summary to stdout
    Returns NmapProcess object for further use
    
    TODO - catch keyboard interrupts and kill tasks so we can exit gracefully!
            nmap_proc.stop does not appear to fully kill threads in script scans
            so program will continue to execute but leaves an orphaned nmap process
    '''
    status_update_interval = 5
    
    #Check for sudo and disable scan options that require root
    if os.getuid()!=0:
        logging.warn("Certain nmap scans require root privileges (SYN, UDP, ICMP, etc)...")
        logging.warn("Disabling incompatible scan types and OS / service version detection options if enabled")
        scan_options = scan_options.replace("-sS", "-sT")
        scan_options = scan_options.replace("-sU", "")
        scan_options = scan_options.replace("-sP", "")
        scan_options = scan_options.replace("-sn", "")
        scan_options = scan_options.replace("-sV", "")
        scan_options = scan_options.replace("-O", "")
    
    nmap_proc = NmapProcess(targets=scan_targets, options=scan_options)
    print "Running scan command:\n"+nmap_proc.command
    nmap_proc.run_background()
    
    while nmap_proc.is_running():
        try:
            time.sleep(status_update_interval)
            
            if nmap_proc.progress > 0:
                
                #Nmap only updates ETC periodically and will sometimes return a result that is behind current system time
                etctime = datetime.datetime.fromtimestamp(int(nmap_proc.etc))
                systime = datetime.datetime.now().replace(microsecond=0)
                if etctime < systime:
                    etctime = systime
                timeleft = etctime - systime
                print("{0} Timing: About {1}% done; ETC: {2} ({3} remaining)".format(nmap_proc.current_task.name, nmap_proc.progress, etctime, timeleft))
        except KeyboardInterrupt:
            print "Keyboard Interrupt - Killing Current Nmap Scan!"
            nmap_proc.stop()
        
    if nmap_proc.rc == 0:
        print nmap_proc.summary + "\n"
    else:
        print nmap_proc.stderr + "\n"
    
    return nmap_proc
开发者ID:AnarKyx01,项目名称:autoenum,代码行数:52,代码来源:nmap.py

示例2: do_scan

# 需要导入模块: from libnmap.process import NmapProcess [as 别名]
# 或者: from libnmap.process.NmapProcess import stop [as 别名]
 def do_scan(self):
     """scan start flag"""
     if(self._flg_is_scanning != True):
         self._flg_is_scanning = True
     if(self._flg_scan_finished != False):
         self._flg_scan_finished = False
     """运行次数初始化"""
     trycnt = 0
     while True:
         """运行时间初始化"""
         runtime = 0
         if trycnt >= self.retrycnt:
             print '-' * 50
             return 'retry overflow'
         try:
             nmap_proc = NmapProcess(targets=self.targets,options=self.options,safe_mode=False)
             self._flg_is_scanning = True    
             nmap_proc.run_background()
             while(nmap_proc.is_running()):
                 """运行超时,结束掉任务,休息1分钟,再重启这个nmap任务"""
                 if runtime >= self.timeout:
                     print '-' * 50
                     print "timeout....terminate it...."
                     nmap_proc.stop()
                     """休眠时间"""
                     sleep(60)
                     trycnt += 1
                     break
                 else:
                     print 'running[%ss]:%s' %(runtime,nmap_proc.command)
                     sleep(5)
                     runtime += 5
             if nmap_proc.is_successful():
                 """scan finished flag"""
                 if(self._flg_is_scanning != False):
                     self._flg_is_scanning = False
                 if(self._flg_scan_finished != True):
                     self._flg_scan_finished = True
                     
                 print '-' * 50
                 print nmap_proc.summary
                 return nmap_proc.stdout
         except Exception,e:
             print e
             trycnt +=1
             if trycnt >= retrycnt:
                 print '-' * 50
                 print 'retry overflow'
                 return e
开发者ID:wangyouzi,项目名称:Wscan,代码行数:51,代码来源:ZServerScanner.py

示例3: do_nmap_scan

# 需要导入模块: from libnmap.process import NmapProcess [as 别名]
# 或者: from libnmap.process.NmapProcess import stop [as 别名]
def do_nmap_scan(targets, options=global_options):
	# 运行次数初始化
	trycnt = 0

	while True:
		# 运行时间初始化
		runtime = 0

		if trycnt >= retrycnt:
			print '-' * 50
			return 'retry overflow'

		try:
			nmap_proc = NmapProcess(targets=targets, options=options, safe_mode=False)
			nmap_proc.run_background()

			while nmap_proc.is_running():
				if runtime >= timeout:	# 运行超时,结束掉任务,休息1分钟, 再重启这个nmap任务
					print '-' * 50
					print "* timeout. terminate it..."
					nmap_proc.stop()
					# 休眠时间
					sleep(60)
					trycnt += 1
					break
				else:
					print 'running[%ss]:%s' % (runtime, nmap_proc.command)
					sleep(5)
					runtime += 5
			if nmap_proc.is_successful():
				print '-' * 50
				print nmap_proc.summary
				return nmap_proc.stdout

		except Exception, e:
			# raise e
			print e
			trycnt += 1
			if trycnt >= retrycnt:
				print '-' * 50
				print '* retry overflow'
				return e
开发者ID:0x24bin,项目名称:wyportmap,代码行数:44,代码来源:wyportmap.py

示例4: do_nmap_scan

# 需要导入模块: from libnmap.process import NmapProcess [as 别名]
# 或者: from libnmap.process.NmapProcess import stop [as 别名]
def do_nmap_scan(targets, options=NMAP_GLOBAL_OPTIONS):
    # 运行次数初始化
    trycnt = 0

    while True:
        # 运行时间初始化
        runtime = 0

        if trycnt >= NMAP_RETRYCNT:
            print "-" * 50
            return "retry overflow"

        try:
            nmap_proc = NmapProcess(targets=targets, options=options, safe_mode=False)
            nmap_proc.run_background()

            while nmap_proc.is_running():
                if runtime >= NMAP_TIMEOUT:  # 运行超时,结束掉任务,休息1分钟, 再重启这个nmap任务
                    print "-" * 50
                    print "* timeout. terminate it..."
                    nmap_proc.stop()
                    # 休眠时间
                    time.sleep(60)
                    trycnt += 1
                    break
                else:
                    print "running[%ss]:%s" % (runtime, nmap_proc.command)
                    time.sleep(5)
                    runtime += 5
            if nmap_proc.rc == 0:
                return nmap_proc.stdout

        except Exception, e:
            # raise e
            print e
            trycnt += 1
            if trycnt >= NMAP_RETRYCNT:
                print "-" * 50
                print "* retry overflow"
                return e
开发者ID:xujun10110,项目名称:examples,代码行数:42,代码来源:tasks.py

示例5: NmapProcess

# 需要导入模块: from libnmap.process import NmapProcess [as 别名]
# 或者: from libnmap.process.NmapProcess import stop [as 别名]
#!/usr/bin/env python

from libnmap.process import NmapProcess
from time import sleep


nmap_proc = NmapProcess(targets="scanme.nmap.org", options="-sV")
nmap_proc.run_background()
while nmap_proc.is_running():
    nmaptask = nmap_proc.current_task
    if nmaptask:
        print("Task {0} ({1}): ETC: {2} DONE: {3}%".format(nmaptask.name,
                                                           nmaptask.status,
                                                           nmaptask.etc,
                                                           nmaptask.progress))
    sleep(3)
    nmap_proc.stop()

print("rc: {0} output: {1}".format(nmap_proc.rc, nmap_proc.summary))
print(nmap_proc.stdout)
print(nmap_proc.stderr)
开发者ID:CaiJiJi,项目名称:python-libnmap,代码行数:23,代码来源:stop_scan.py


注:本文中的libnmap.process.NmapProcess.stop方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。