fr54-public-route-probe.py

"""Read-only public GETs; default certificate verification, no redirect bypass."""
import datetime
import hashlib
import json
import urllib.error
import urllib.request

class NoRedirect(urllib.request.HTTPRedirectHandler):
    def redirect_request(self, *args, **kwargs):
        return None

opener = urllib.request.build_opener(NoRedirect())
results = []
for host in ('mizoki3.com', 'tech.mizoki3.com'):
    for path in ('/blogs', '/blogs/', '/blogs.html', '/blog', '/11/'):
        url = 'https://' + host + path
        row = {'url': url, 'time': datetime.datetime.now(datetime.timezone.utc).isoformat()}
        try:
            response = opener.open(urllib.request.Request(url, headers={'User-Agent': 'Mizoki-readiness-route-verification/1.0'}), timeout=20)
        except urllib.error.HTTPError as exc:
            response = exc
        except Exception as exc:
            row['error'] = str(exc)
            results.append(row)
            continue
        body = response.read(1000000)
        row.update(status=response.code, location=response.headers.get('Location'),
                   server=response.headers.get('Server'), body_sha256=hashlib.sha256(body).hexdigest())
        results.append(row)
print(json.dumps(results, indent=2))
← All docsView source on GitHub →