大家好,这是我的第一个从现实需求出发的Python小程序
破东校园网在笔记本待机唤醒之后需要断开重连,而使用期间也会经常异常断线……
偶然在优快云上看到了学长写的文章,解决了类似的问题,于是按照这个思路再找了其他的资料,写了一个基本功能完整的小程序~
希望能给看到的人一些启发~
(可爱的人果然写出来的代码也很可爱啊)
全部代码:
import os
from selenium import webdriver
from bs4 import BeautifulSoup
import time
import requests
import ctypes
count = 0
username_str = "一卡通号"#一卡通号
password_str = "统一认证密码"#统一认证密码
#Action of reconnect
#return: True-reconnect success
#return: False-reconnect fail
def reconnect():
try:
os.system('netsh wlan disconnect')
except:
print(getCurrentTime(),'( ̄(工) ̄b)断开连接失败')
time.sleep(1)
try:
os.system("netsh wlan connect name=%s" % 'seu-wlan')
time.sleep(1)
return True
except:
print(getCurrentTime(),'( ̄(工) ̄b)连不上校园网')
time.sleep(1)
return False
##Check accessibility of network
#return: 0-not connected
#return: 1-w.seu.edu.cn only
#return: 2-domestic only
#return: 3-free network
def network_status():
#Simplified
try:
requests.get("http://cn.bing.com")
flag = 1
except:
flag = 0
#Simplified
if flag==1:
try:
requests.get("http://www.google.com")
return 3
except:
return 2
else:
try:
requests.get("http://w.seu.edu.cn")
return 1
except:
return 0
#注销再登陆函数
#返回值:True-登录成功;False-刷不出登录界面
def login():
#浏览器是否能打开
try:
driver = webdriver.Chrome()
driver.get("https://w.se