Skip to content

Instantly share code, notes, and snippets.



Last active Jan 6, 2020
What would you like to do?
Quick Internet Connectivity Test: Invokes a connect on Google's public DNS server: with a socket timeout of 1 second.
import socket
def internet(host="", port=53, timeout=3):
Host: (
OpenPort: 53/tcp
Service: domain (DNS/TCP)
socket.socket(socket.AF_INET, socket.SOCK_STREAM).connect((host, port))
return True
except Exception as ex:
print ex.message
return False

This comment has been minimized.

Copy link
Owner Author

@7h3rAm 7h3rAm commented Oct 14, 2015


This comment has been minimized.

Copy link

@acrolink acrolink commented Jan 1, 2020

Won't checking internet connection by accessing port 53 on every 5 seconds lead possibly to getting client's IP blocked by Google (get marked as abuse)?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.