Skip to content

Instantly share code, notes, and snippets.

@7h3rAm

7h3rAm/internet.py

Last active Jan 6, 2020
Embed
What would you like to do?
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.
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
@7h3rAm

This comment has been minimized.

Copy link
Owner Author

@7h3rAm 7h3rAm commented Oct 14, 2015

@acrolink

This comment has been minimized.

Copy link

@acrolink acrolink commented Jan 1, 2020

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
You can’t perform that action at this time.