-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathauto-wifi-switcher.py
61 lines (57 loc) · 1.71 KB
/
auto-wifi-switcher.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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
import requests
import json
import os, platform
import time
import datetime
import winwifi
Primary_SSID='!....KENTHELL...!'
Secondary_SSID='....Kent Hell 2...'
def check_ping():
hostname = "8.8.8.8"
pingstatus=1
active=0
error=0
pingList = []
for x in range(5):
time.sleep(1)
response = os.system("ping -n 1 " + hostname)
pingList.append(response)
print("\n"+"---------------------------------------------"+"\n")
for i in pingList:
if i == 0:
active += 1
else:
error += 1
print("Active:"+str(active))
print("Error:"+str(error))
if active > error:
pingstatus = "Active"
else:
pingstatus = "Error"
return pingstatus
def change_wifi(status):
print("STATUS: "+ status)
if status == "Error":
print("Switching to "+Secondary_SSID)
time.sleep(1)
winwifi.WinWiFi.connect(Secondary_SSID)
print("Switched to "+Secondary_SSID)
time_now=datetime.datetime.now()
file = open("change.log", "a")
file.write(time_now.strftime("%m/%d/%Y, %H:%M:%S")+" ::Failover to: "+Secondary_SSID + "\n")
file.close()
print("Waiting one minute to failover to "+Primary_SSID)
time.sleep(60)
winwifi.WinWiFi.connect(Primary_SSID)
time_now=datetime.datetime.now()
file = open("change.log", "a")
file.write(time_now.strftime("%m/%d/%Y, %H:%M:%S")+" ::Successfully Failback to: "+Primary_SSID + "\n")
file.close()
print("Waiting few mnitues to restart the script")
time.sleep(30)
print("Successfully failover to "+Primary_SSID)
else:
print("No Issues observed")
while 1 < 6:
pingstatus = check_ping()
change_wifi(pingstatus)