-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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