python wifi event code example
Example: python - how to get an on wifi access event
import socket
import time
import subprocess
def check():
try:
host = socket.gethostbyname("www.google.com")
s = socket.create_connection((host, 80), 2)
return True
except Exception:
return False
while True:
if check() == True:
DoSomeStuff()
else:
subprocess.call(["/bin/bash", "-c", "rfkill", "block", "wifi"])
subprocess.call(["/bin/bash", "-c", "rfkill", "unblock", "wifi"])
subprocess.Popen(["/bin/bash", "-c", "notify-send 'conncection re-established'"])
time.sleep(4)