代码语言:javascript复制
使用Ulipad编辑的
#! /usr/bin/env python
#coding=utf-8
#############
import subprocess
import time
ip="10.210.202."
#############
def aa():
ks=int(time.time()) #记录开始时间
num1=num2=0
for i in range(1,254):
ips=ip str(i)
ret=subprocess.call("ping -n 1 -w 1 %s " % ips)
if ret == 0:
print (ips," Online ")
num1=num1 1
else:
# print (ips,"-------------Offline")
num2=num2 1
js=int(time.time()) #记录结束时间
print("time(秒):",js-ks,"s") #打印并计算用的时间,s秒
print("ON_line:",num1," OFF_line:",num2)
while True:
aa()
hd=input("是否继续【Y/N】:")
try:
if hd=="Y" or hd=="y":
pass
except :pass
if hd=="N" or hd=="n":
print("Goodbye!......")
time.sleep(3)
break
效果图如下: