本文整理匯總了Python中ipcalc.Network.host_first方法的典型用法代碼示例。如果您正苦於以下問題:Python Network.host_first方法的具體用法?Python Network.host_first怎麽用?Python Network.host_first使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類ipcalc.Network
的用法示例。
在下文中一共展示了Network.host_first方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: main
# 需要導入模塊: from ipcalc import Network [as 別名]
# 或者: from ipcalc.Network import host_first [as 別名]
def main():
parser = OptionParser()
parser.add_option("-m", "--multithread", dest="multithread", help="number of threads for concurrency, default is 10")
parser.add_option("-t", "--target", dest="target", help="Target ip in network to scan -t 192.168.192.0.10/24")
parser.add_option("-s", "--sleeping", dest="sleeping", help="Seconds to sleep after one cycle, default is 1")
parser.add_option("-f", "--filename", dest="filename", help="the file to record recent counting result")
parser.add_option("-j", "--maxjump", dest="maxjump", help="if more than MAXJUMP continuous IPv4 addresses not respond, stop")
parser.add_option("-w", "--timeout", dest="timeout", help="Ping timeout, default: 2")
parser.add_option("-c", "--count", dest="count", help="Stop after sending <count> requests to host, default: 1")
parser.add_option("-i", "--interval", dest="interval", help="Wait <interval> seconds between sending packet, default: 0.2")
(options, args) = parser.parse_args()
if not options.target or not '/' in options.target:
print "please specify a target: -t 192.168.0.10/24"
print "use -h to view helping text"
return
interval = (options.interval if options.interval else '0.1')
timeout = (options.timeout if options.timeout else '1')
count = (options.count if options.count else '1')
multithread = (int(options.multithread) if options.multithread else 10)
sleeping = (int(options.sleeping) if options.sleeping else 1)
target = options.target
filename = (options.filename if options.filename else './subnet_count')
maxjump = (int(options.maxjump) if options.maxjump else 256*256*256*256)
net = Network(target)
DEVNULL = open(os.devnull, 'w')
commands.getstatusoutput("echo "+str(0)+" > "+filename)
global alive_num
global last_alive_index
while(1):
alive_num = 0
last_alive_index = 0
index = 0
thread_pool = []
need_to_ping = Network(str(net.host_first()) + '/' + target.split('/')[1])
for ip in need_to_ping:
index += 1
if(index-last_alive_index > maxjump):
break;
t = PingOne(interval,timeout,count,ip,index,DEVNULL)
thread_pool.append(t)
if( index > 0 and index % multithread == 0):
for tt in thread_pool:
tt.start()
for tt in thread_pool:
tt.join()
thread_pool[:] = []
# last turn
if thread_pool:
for tt in thread_pool:
tt.start()
for tt in thread_pool:
tt.join()
thread_pool[:] = []
commands.getstatusoutput("echo "+str(alive_num)+" > "+filename)
print "find "+str(alive_num)+" alive ipv4 addresses"
time.sleep(sleeping)