Answers for "python check if there is internet"

2

python check if internet is available

import urllib.request

def internet_on():
    try:
        urllib.request.urlopen('http://216.58.192.142', timeout=2)
        return True
    except:
        return False
Posted by: Guest on December-30-2020
1

python check if there is internet

try:
    import httplib  # python < 3.0
except:
    import http.client as httplib


def have_internet():
    conn = httplib.HTTPSConnection("8.8.8.8", timeout=5)
    try:
        conn.request("HEAD", "/")
        return True
    except Exception:
        return False
    finally:
        conn.close()
Posted by: Guest on April-28-2022

Code answers related to "python check if there is internet"

Python Answers by Framework

Browse Popular Code Answers by Language