-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Full Commit - Transferred from other repo
- Loading branch information
1 parent
945ff8b
commit f47c76e
Showing
33 changed files
with
3,504,272 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
''' | ||
Online test: https://tools.keycdn.com/http2-test | ||
Source: https://geekflare.com/python-script-http2-test/ | ||
Note: There may be a tradeoff between latency/accuracy that is | ||
affected by socket.setdefaulttimeout value | ||
''' | ||
|
||
import socket | ||
import ssl | ||
from urllib.parse import urlparse | ||
|
||
socket.setdefaulttimeout(5) | ||
|
||
# Returns True if site has adopted HTTP/2.0, False otherwise | ||
def check(url): | ||
try: | ||
HOST = urlparse("http://www."+url).netloc | ||
PORT = 443 | ||
|
||
context = ssl.create_default_context() | ||
context.set_alpn_protocols(['h2', 'spdy/3', 'http/1.1']) | ||
|
||
connection = context.wrap_socket( | ||
socket.socket(socket.AF_INET, socket.SOCK_STREAM), | ||
server_hostname=HOST) | ||
connection.connect((HOST, PORT)) | ||
|
||
if connection.selected_alpn_protocol() == "h2": | ||
return True | ||
|
||
except Exception: | ||
pass | ||
|
||
return False | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
''' | ||
Online test: https://ipv6-test.com/validate.php | ||
Source: https://github.com/danyork/aaaa-check/blob/master/aaaa-check.py | ||
Note: There may be a tradeoff between latency/accuracy that is | ||
affected by resolver.timeout and resolver.lifetime values | ||
''' | ||
|
||
import socket | ||
import dns.resolver | ||
|
||
# Returns True if url is IPv6 reachable, False otherwise | ||
def check(url): | ||
try: | ||
ipv = socket.getaddrinfo(url, 80, family=socket.AF_INET6) | ||
|
||
# Query for A, AAAA DNS records | ||
resolver = dns.resolver.Resolver() | ||
resolver.timeout = 1 | ||
resolver.lifetime = 1 | ||
answer_A = dns.resolver.query(url, "A") | ||
answer_AAAA = dns.resolver.query(url, "AAAA") | ||
|
||
# If there is IPv6 address and DNS queries do not fail, return True | ||
if ipv[0][0].name == "AF_INET6": | ||
return True | ||
|
||
# Else, socket.getaddrinfo or dns.resolver.query failed somehow | ||
except (socket.gaierror, dns.resolver.NXDOMAIN, | ||
dns.resolver.NoAnswer, dns.resolver.NoNameservers, | ||
dns.exception.Timeout, dns.resolver.YXDOMAIN): | ||
pass | ||
|
||
return False |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
import csv | ||
import requests | ||
from io import BytesIO | ||
from zipfile import ZipFile | ||
|
||
alexa_url = "http://s3.amazonaws.com/alexa-static/top-1m.csv.zip" | ||
req = requests.get(alexa_url) | ||
zf = ZipFile(BytesIO(req.content)) | ||
zf.extractall() | ||
|
||
d = {} | ||
with open('top-1m.csv') as f: | ||
reader = csv.reader(f) | ||
for row in reader: | ||
d[int(row[0])] = row[1] | ||
|
||
print(len(d), "items parsed") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
import socket | ||
import ssl | ||
import re | ||
import threading | ||
import sys | ||
from urllib.parse import urlparse | ||
|
||
socket.setdefaulttimeout(20) | ||
|
||
def check_http2(domain): | ||
try: | ||
if 'www' in domain: | ||
host = urlparse("http://" + domain).netloc | ||
else: | ||
host = urlparse("http://www." + domain).netloc | ||
port = 443 | ||
context = ssl.create_default_context() | ||
context.set_alpn_protocols(['h2', 'spdy/3', 'http/1.1']) | ||
connection = context.wrap_socket(socket.socket(socket.AF_INET, socket.SOCK_STREAM), server_hostname=host) | ||
connection.connect((host, port)) | ||
except ssl.CertificateError: | ||
err = str(sys.exc_info()) | ||
err = err.split("doesn't match ")[1] | ||
if "either" in err: | ||
err = err.split("either of ")[1] | ||
p = re.compile('\'(.+?)\'"') | ||
m = p.match(err) | ||
try: | ||
host, port = m.group(1), 443 | ||
context = ssl.create_default_context() | ||
context.set_alpn_protocols(['h2', 'spdy/3', 'http/1.1']) | ||
connection = context.wrap_socket(socket.socket(socket.AF_INET, socket.SOCK_STREAM), server_hostname=host) | ||
connection.connect((host, port)) | ||
except: | ||
print(domain, str(sys.exc_info()).split("<class ")[1].split(">,")[0]) | ||
return "error" | ||
except: | ||
print(domain, str(sys.exc_info()).split("<class ")[1].split(">,")[0]) | ||
return "error" | ||
if connection.selected_alpn_protocol() == 'h2': | ||
return "yes" | ||
return "no" | ||
|
||
# print(check_http2('macys.com')) |
Oops, something went wrong.