Code: Select all
import urllib
try:
url = "https://www.google.com"
urllib.urlopen(url)
status = "Connected"
except:
status = "Not connected"
print status
if status == "Connected":
# do stuff...
will check for internet connection.
shows all IP's so if wifi is the only connection you could perhaps say(i dont have a raspberry with me to test this..)
Code: Select all
from subprocess import check_output
wifi_ip = check_output(['hostname', '-I'])
if wifi_ip is not None:
# do stuff...
^ as i recall if nothing is connected the output is nothing, but if it does return something you could always print the output then change None for what ever print returned.