Created
July 1, 2019 06:26
-
-
Save wybiral/2eeb4d4cc3b2ba5e00955b55ec8b1def to your computer and use it in GitHub Desktop.
This file contains hidden or 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
from socket import create_connection | |
from ssl import create_default_context | |
def run_test(addr, httpversion): | |
host, port = addr | |
ctx = create_default_context() | |
with create_connection(addr) as s: | |
with ctx.wrap_socket(s, server_hostname=host) as ss: | |
ss.send(b'GET /robots.txt %s\r\n' % httpversion.encode('utf8')) | |
ss.send(b'Host: %s\r\n' % host.encode('utf8')) | |
ss.send(b'\r\n') | |
line = ss.read(1024) | |
lines = line.split(b'\r\n', 1) | |
if len(lines) != 2: | |
return None | |
parts = lines[0].split(b' ') | |
if len(parts) != 3: | |
return None | |
try: | |
return int(parts[1]) | |
except: | |
return None | |
tests = [ | |
'HTTP/0', | |
'HTTP/1', | |
'HTTP/2', | |
'HTTP/x', | |
'HTTP/0.0', | |
'HTTP/1.0', | |
'HTTP/1.1', | |
'HTTP/1.9', | |
'HTTP/2.0', | |
'HTTP/9.1', | |
'HTTP/x.x', | |
'HTTP/0.00', | |
'HTTP/1.00', | |
'HTTP/1.99', | |
'HTTP/1.999', | |
'HTTP/1.9999', | |
'HTTP/12.0', | |
'HTTP/123.0', | |
] | |
addr = ('github.com', 443) | |
for test in tests: | |
status = run_test(addr, test) | |
if status is None: | |
print(test, '*') | |
else: | |
print(test, status) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment