首页 > 自动化运维 > 大规模网络运维 > 批量检测主机IP(一)
import os
import sys
file = open('log.txt','a')
x = y = 0
for ip in range(1,255):
res = os.system('ping -n 1 -w 1 '+sys.argv[1]+str(ip))
if res == 0:
print(sys.argv[1]+str(ip)+' up')
file.write(sys.argv[1]+str(ip)+' up'+'\n')
x += 1
else:
print(sys.argv[1]+str(ip)+' down')
file.write(sys.argv[1] + str(ip) + ' down'+'\n')
y += 1
print('total up ip is '+str(x))
file.write('total up ip is '+str(x)+'\n')
print('total down ip is '+str(y))
file.write('total down ip is '+str(y))
file.close()
执行 :
python yping.py 192.168.1.
来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/51077/viewspace-2699203/ ,如需转载,请注明出处,否则将追究法律责任。