测试空余IP

#!/bin/env python
#-*- encoding:utf-8  -*-
#该测试没有详细的划分区间,只测试1到xx的全部IP范围

import time,os
start_Time=int(time.time()) #记录开始时间

def init():
    global ip_count
    ip_count = 2   #截止的IP位数


def ip_create():
    init()
    i = 0
    a = []
    while i < ip_count :
        i += 1
        aa = '192.168.1.' + str(i)
        a.append(aa)
    return a


def ping_Test():
    b = ip_create()
    ip_True = []
    ip_False = []

    count_True,count_False=0,0

    for ip in b:
        print ip
        return1=os.system('ping -n 2 -w 1 %s' % ip) #每个ip ping2次,等待时间为1s
        if return1:
            #print 'ping %s is fail' % ip
            ip_False.append(ip)
            count_False += 1
        else:
            #print 'ping %s is ok'%ip
            ip_True.append(ip)
            count_True += 1
    return ip_True,ip_False,count_True,count_False


h = ping_Test()
a , b ,c ,d = h
end_Time = int(time.time())  #记录结束时间
print "运行时间为:%d(秒):" % (end_Time - start_Time)  #打印并计算用的时间
print "剩余IP为:%s" % b




posted @ 2020-08-26 20:57  名字很长容易被惦记  阅读(228)  评论(0编辑  收藏  举报