-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
47 lines (43 loc) · 1.25 KB
/
main.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
import configparser
import requests
import time
import connect
import os
# # 设置不进行代理
os.environ['http_proxy'] = ''
os.environ['https_proxy'] = ''
# 定义常用网站列表
websites = [
'https://baidu.com',
'https://microsoft.com',
]
# 定义 ping 网站函数
def ping_website(url):
try:
response = requests.get(url, timeout=5)
print(response.status_code)
return response.status_code
except requests.exceptions.RequestException as e:
print(f"错误pinging {url}: {e}")
return None
# 主函数
def main():
config = configparser.ConfigParser()
if not os.path.exists('config.ini'):
DDDDD = input("请输入DDDDD: ")
upass = input("请输入upass: ")
config['credentials'] = {'DDDDD': DDDDD, 'upass': upass}
with open('config.ini', 'w') as configfile:
config.write(configfile)
while True:
for website in websites:
status_code = ping_website(website)
if status_code:
print(f"{website} 网站正常,状态码: {status_code}")
else:
if connect.check()==False:
connect.connect()
time.sleep(10)
if __name__ == "__main__":
main()
#connect.check()