Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR PYTHON

python detect internet connection

try:
    import httplib
except:
    import http.client as httplib

def have_internet():
    conn = httplib.HTTPConnection("www.google.com", timeout=5)
    try:
        conn.request("HEAD", "/")
        conn.close()
        return True
    except:
        conn.close()
        return False
# Code by Ivelin on Stack overflow
Source by stackoverflow.com #
 
PREVIOUS NEXT
Tagged: #python #detect #internet #connection
ADD COMMENT
Topic
Name
5+9 =