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 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
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 :: sort first element reverse sort second python 
Python :: creating numpy array using zeros 
Python :: create a timestamp python 
Python :: string print in pattern in python 
Python :: how to write a script to display an image in python 
Python :: python tkinter text get 
Python :: match python 3.10 
Python :: word2number python 
Python :: randomly shuffle array python 
Python :: builtwith python 
Python :: app is not a registered namespace django 
Python :: how to make python file executable 
Python :: filter in pandas 
Python :: python 7zip extract 
Python :: How to join train and Test dataset in python 
Python :: user defined functions python 
Python :: drop rows where specific column has null values 
Python :: python assert is not null 
Python :: django only certain columns from database 
Python :: python venv flask 
Python :: python negative indexing 
Python :: python async partial function 
Python :: Python string to var 
Python :: scatter matrix plot 
Python :: make legend box transparent in matplotlib 
Python :: how to make a discord bot in python 
Python :: sentence similarity spacy 
Python :: torch flatten 
Python :: python replace 
Python :: python while continue 
ADD CONTENT
Topic
Content
Source link
Name
1+8 =