34 lines
933 B
Python
34 lines
933 B
Python
import urllib.request
|
|
import ssl
|
|
import sys
|
|
|
|
sys.stdout.reconfigure(encoding='utf-8')
|
|
|
|
ctx = ssl.create_default_context()
|
|
ctx.check_hostname = False
|
|
ctx.verify_mode = ssl.CERT_NONE
|
|
|
|
urls = [
|
|
"https://pihole1.snarfnet.net",
|
|
"https://pihole2.snarfnet.net",
|
|
"https://dns1.snarfnet.net",
|
|
"https://dns2.snarfnet.net"
|
|
]
|
|
|
|
class NoRedirectHandler(urllib.request.HTTPRedirectHandler):
|
|
def redirect_request(self, req, fp, code, msg, headers, newurl):
|
|
return None
|
|
|
|
opener = urllib.request.build_opener(NoRedirectHandler)
|
|
|
|
for url in urls:
|
|
req = urllib.request.Request(url, headers={"User-Agent": "Mozilla/5.0"})
|
|
try:
|
|
resp = opener.open(req, timeout=5)
|
|
print(f"{url} -> {resp.status} {resp.reason}")
|
|
except urllib.error.HTTPError as e:
|
|
print(f"{url} -> {e.code} {e.reason} (Location: {e.headers.get('Location')})")
|
|
except Exception as e:
|
|
print(f"{url} -> Error: {e}")
|
|
|