Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

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
Comment

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()
Comment

python check if there is internet connection

# pip install pythonping
from pythonping import ping
def internet_connected(test_ip_address="8.8.8.8"):
    return ping(test_ip_address).success()
Comment

PREVIOUS NEXT
Code Example
Python :: convert python list to text file 
Python :: add seconds to datetime python 
Python :: color to black and white cv2 
Python :: python list of random values 
Python :: save plot python 
Python :: get list of folders in directory python 
Python :: python reimport py file 
Python :: how to fillna in all columns with their mean values 
Python :: how to install mediapipe python 
Python :: selenium refresh page python 
Python :: correlation plot python seaborn 
Python :: download pdf from link using python 
Python :: pandas update with condition 
Python :: pandas add days to date 
Python :: pig latin translator python 
Python :: ubuntu install python 3.8 
Python :: write to txt python 
Python :: python find dict in list of dict by id 
Python :: how to estimate process timing python 
Python :: return count of unique values pandas 
Python :: load model keras 
Python :: python current time 
Python :: python mean and standard deviation of list 
Python :: discord py bot status 
Python :: print json python 
Python :: python hand tracking module 
Python :: if type is string python 
Python :: python3 base64 encode basic authentication 
Python :: flask run app reset on change 
Python :: how to replace a word in csv file using python 
ADD CONTENT
Topic
Content
Source link
Name
2+5 =