from time import sleep
from subprocess import run, PIPE
cnt = 1
while True:
# shell命令
r = run('ping www.baidu.com',
stdout=PIPE,
stderr=PIPE,
stdin=PIPE,
shell=True)
if r.returncode:
print('网络连接失败 第{}次'.format(cnt))
# login() 这里写login函数
cnt += 1
else:
print('网络连接成功')
# sleep(60*30) # 每半个小时检查一次



