Last active
April 26, 2021 20:57
-
-
Save 7h3rAm/a4c3de8e502f755a7253 to your computer and use it in GitHub Desktop.
Quick Internet Connectivity Test: Invokes a connect on Google's public DNS server: 8.8.8.8:53/TCP with a socket timeout of 1 second.
This file contains hidden or 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 internet(host="8.8.8.8", port=53, timeout=3): | |
""" | |
Host: 8.8.8.8 (google-public-dns-a.google.com) | |
OpenPort: 53/tcp | |
Service: domain (DNS/TCP) | |
""" | |
try: | |
socket.setdefaulttimeout(timeout) | |
socket.socket(socket.AF_INET, socket.SOCK_STREAM).connect((host, port)) | |
return True | |
except Exception as ex: | |
print ex.message | |
return False |
Won't checking internet connection by accessing port 53 on 8.8.8.8 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
StackOverflow Answer: http://stackoverflow.com/a/33117579/1079836