Skip to content

Instantly share code, notes, and snippets.

@wybiral
Created April 4, 2021 18:25
Show Gist options
  • Save wybiral/b106d4625d986334b21e228152158e72 to your computer and use it in GitHub Desktop.
Save wybiral/b106d4625d986334b21e228152158e72 to your computer and use it in GitHub Desktop.
Test different HTTP version lines against a list of addresses
from socket import create_connection
from ssl import create_default_context
def run_test(addr, path, 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 %s %s\r\n' % (
path.encode('utf8'),
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
path = '/robots.txt'
tests = [
'HTTP/1',
'HTTP/0.0',
'HTTP/1.0',
'HTTP/1.1',
'HTTP/1.9',
'HTTP/2.0',
'HTTP/9.1',
'HTTP/x.x',
'HTTP/1.00',
'HTTP/1.000',
'HTTP/1.0000',
'HTTP/12.0',
'HTTP/123.0',
'HTML/1.0',
'DAVY/1.0',
]
addrs = [
('amazon.com', 443),
('craigslist.org', 443),
('ebay.com', 443),
('en.wikipedia.org', 443),
('facebook.com', 443),
('google.com', 443),
('hulu.com', 443),
('imdb.com', 443),
('instagram.com', 443),
('linkedin.com', 443),
('netflix.com', 443),
('reddit.com', 443),
('tiktok.com', 443),
('twitter.com', 443),
('urbandictionary.com', 443),
('walmart.com', 443),
('weather.com', 443),
('yelp.com', 443),
('youtube.com', 443),
]
fp = open('results.txt', 'w')
line = ['Site']
for test in tests:
line.append(test)
fp.write('\t'.join(line) + '\n')
for addr in addrs:
print('\nScanning: ' + addr[0])
line = [addr[0]]
for test in tests:
try:
status = run_test(addr, path, test)
except KeyboardInterrupt:
exit(1)
except:
status = None
if status is None:
line.append('')
print(' ', test, 'error')
else:
line.append(str(status))
print(' ', test, status)
fp.write('\t'.join(line) + '\n')
fp.close()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment