通过使用python,编写脚本批量ping主机,验证主机是否处于活动状态
#!/usr/bin/python #auther: Jacky #date: 2016-08-01 #filename: ping_ip.py import os,sys import subprocess,cmd def subping(): f = open("ip_list.txt","r") lines = f.readlines() for line in lines: line=line.strip(‘\n‘) ret = subprocess.call("ping -c 2 -w 5 %s" % line,shell=True,stdout=subprocess.PIPE) if ret == 0: str = ‘%s is alive‘ % line print str elif ret == 1: str = ‘%s is not alive‘ % line print str f.close() subping()
主机列表文件名ip_list.txt
192.168.56.12 192.168.56.13 192.168.56.14
时间: 2024-10-12 04:10:32