Skip to content

Instantly share code, notes, and snippets.

@kitusmark
Forked from rayansostenes/haveInternet.py
Created December 15, 2015 17:09
Show Gist options
  • Save kitusmark/7aa8ad36a7a163fa0288 to your computer and use it in GitHub Desktop.
Save kitusmark/7aa8ad36a7a163fa0288 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