diff --git a/ruijie.py b/ruijie.py index 1c200cd..0a3af75 100644 --- a/ruijie.py +++ b/ruijie.py @@ -8,6 +8,7 @@ linkpath = shuPath() + class shuConnect: def __init__(self, user=0, passwd='shu'): self.user = user diff --git a/wifiConnect.py b/wifiConnect.py index 687ae04..24a35b5 100644 --- a/wifiConnect.py +++ b/wifiConnect.py @@ -8,7 +8,7 @@ def wifi_connect_status(user, passwd): - if not psutil.net_if_stats()[nameHi].isup: # wifi未连接到wifi或未打开WiFi开关 + if not psutil.net_if_stats()[nameHi].isup: # wifi未连接到Shu(ForAll) 或未打开WiFi开关 try: s = connect_wifi(user, passwd) except Exception as e: @@ -30,25 +30,25 @@ def wifi_connect_status(user, passwd): def connect_wifi(user, passwd): - wifi = PyWiFi() # 创建一个wifi对象 - iface = wifi.interfaces()[0] # 取第一个无限网卡 - iface.disconnect() # 断开网卡连接 + try: + wifi = PyWiFi() # 创建一个wifi对象 + iface = wifi.interfaces()[0] # 取第一个无限网卡 - profile = Profile() # 配置文件 - profile.ssid = "Shu(ForAll)" # wifi名称 + iface.disconnect() # 断开网卡连接 + profile = Profile() # 配置文件 + profile.ssid = "Shu(ForAll)" # wifi名称 - iface.remove_all_network_profiles() # 删除其他配置文件 - tmp_profile = iface.add_network_profile(profile) # 加载配置文件 + iface.remove_all_network_profiles() # 删除其他配置文件 + tmp_profile = iface.add_network_profile(profile) # 加载配置文件 - iface.connect(tmp_profile) # 连接 - sleep(1.5) # 不延时,状态码来不及改变 + iface.connect(tmp_profile) # 连接 + sleep(0.5) # 不延时,wifi反应不过来 - if iface.status() == const.IFACE_CONNECTED: s0 = "Shu(ForAll) 连接成功\n" shu = shuConnect(user, passwd) s = s0 + shu.start_connect() - else: + except: s = "无线网卡未打开,请打开 WLAN 开关\n" return s