Skip to content

Commit

Permalink
function check if connected
Browse files Browse the repository at this point in the history
  • Loading branch information
jdebacker committed Aug 3, 2024
1 parent 5214301 commit 0d55f44
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions ogzaf/utils.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import requests
import urllib3
import ssl
import socket


class CustomHttpAdapter(requests.adapters.HTTPAdapter):
Expand Down Expand Up @@ -29,3 +30,15 @@ def get_legacy_session():
session = requests.session()
session.mount("https://", CustomHttpAdapter(ctx))
return session


# Function to check if connected to internet
def is_connected():
try:
# connect to the host -- tells us if the host is actually
# reachable
socket.create_connection(("1.1.1.1", 53))
return True
except OSError:
pass
return False

0 comments on commit 0d55f44

Please sign in to comment.