Skip to content

Instantly share code, notes, and snippets.

@rayansostenes
Created July 19, 2015 03:33
Show Gist options
  • Save rayansostenes/6742ee47627b6ab717ed to your computer and use it in GitHub Desktop.
Save rayansostenes/6742ee47627b6ab717ed to your computer and use it in GitHub Desktop.
A python method to check if the system have a active connection to the internet
import socket
def haveInternet():
REMOTE_SERVER = "www.google.com"
try:
host = socket.gethostbyname(REMOTE_SERVER)
s = socket.create_connection((host, 443))
return True
except:
pass
return False
print haveInternet()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment