优化终端显示
This commit is contained in:
parent
4151b5796b
commit
f5148e7d34
48
main.py
48
main.py
@ -3,44 +3,58 @@ import os, time ,requests
|
|||||||
def network_test():
|
def network_test():
|
||||||
try:
|
try:
|
||||||
html = requests.get("https://www.baidu.com",timeout=5)
|
html = requests.get("https://www.baidu.com",timeout=5)
|
||||||
print("{} network 200 , ok".format(time.ctime()))
|
|
||||||
return True
|
return True
|
||||||
except:
|
except:
|
||||||
print("{} network 403 , down".format(time.ctime()))
|
|
||||||
return False
|
return False
|
||||||
|
|
||||||
def network_restart():
|
def network_restart():
|
||||||
print("正在重启en0..")
|
|
||||||
try:
|
try:
|
||||||
os.system("ifconfig en0 down")
|
os.system("ifconfig en0 down")
|
||||||
print("关闭en0...")
|
|
||||||
except:
|
except:
|
||||||
print("关闭en0失败!")
|
|
||||||
return False
|
return False
|
||||||
time.sleep(1)
|
time.sleep(1)
|
||||||
try:
|
try:
|
||||||
os.system("ifconfig en0 up")
|
os.system("ifconfig en0 up")
|
||||||
print("启动en0...")
|
|
||||||
except:
|
except:
|
||||||
print("启动en0失败!")
|
|
||||||
return False
|
return False
|
||||||
return True
|
return True
|
||||||
|
|
||||||
|
def ascii_tag():
|
||||||
|
sys_s = None
|
||||||
|
sta_s = None
|
||||||
|
if i > 0:
|
||||||
|
sys_s = "Down"
|
||||||
|
sta_s = "{} network 403 , down".format(time.ctime())
|
||||||
|
else:
|
||||||
|
sys_s = "Up"
|
||||||
|
sta_s = "{} network 200 , ok".format(time.ctime())
|
||||||
|
os.system("clear")
|
||||||
|
print(" _ _ _______ ")
|
||||||
|
print(" / \ / |_ |_ __ \ ")
|
||||||
|
print(" / _ \ __ _ `| |-' .--. | |__) | .---. ")
|
||||||
|
print(" / ___ \ [ | | | | | / .'`\ \ | __ / / /__\\ ")
|
||||||
|
print(" _/ / \ \_ | \_/ |,| |,| \__. |_| | \ \_| \__., ")
|
||||||
|
print("|____| |____|'.__.'_/\__/ '.__.'|____| |___|'.__.' ")
|
||||||
|
print("")
|
||||||
|
print("系统架构:{}\n异常次数:{}\n当前状态:{}\n最近记录:{}".format(os.name,j,sys_s,sta_s))
|
||||||
|
return True
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
|
global i ,j
|
||||||
i = 0
|
i = 0
|
||||||
|
j = 0
|
||||||
while(1):
|
while(1):
|
||||||
if not network_test():
|
ascii_tag()
|
||||||
i +=1
|
if not network_test(): #网络异常
|
||||||
print(i)
|
i +=1 #异常计数 3次失败重启
|
||||||
time.sleep(3)
|
time.sleep(3)
|
||||||
else:
|
else: #网络正常
|
||||||
|
i = 0
|
||||||
time.sleep(10)
|
time.sleep(10)
|
||||||
if (i > 2):
|
if (i > 2): #异常3次
|
||||||
if not network_restart():
|
if not network_restart(): #接口重启失败
|
||||||
print("异常,程序退出!")
|
input()
|
||||||
exit()
|
else: #接口重启完成
|
||||||
else:
|
|
||||||
print("完成!")
|
|
||||||
i = 0
|
i = 0
|
||||||
time.sleep(10)
|
time.sleep(10)
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user