#!/root/kl/bin/python3
# author:kl
#多线程查看服务器状态
import subprocess
import threading
class Ping():
def __init__(self, ip):
self.ip = ip
def __call__(self):
result = subprocess.run('ping -c 2 %s &>/dev/null'
% self.ip, shell=True)
if result.returncode == 0:
print('%s:up' % self.ip)
else:
print('%s:down' % self.ip)
if __name__ == '__main__':
ips = ('176.233.1.%s' % i for i in range(1, 255))
for ip in ips:
# 创建工作线程
t = threading.Thread(target=Ping(ip))
# 启动工作线程,就是调用相应的函数,函数结束,线程也就结束了
t.start() # 调用target(*args)
python多线程查看服务器状态
最新推荐文章于 2024-07-09 21:30:00 发布