Created
July 29, 2018 12:26
-
-
Save gainskills/b85a8173aaf05b2f753042d59b5baf9c to your computer and use it in GitHub Desktop.
HTTP/HTTPs site-POPs
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
import requests | |
from forcediphttpsadapter.adapters import ForcedIPHTTPSAdapter | |
import urllib3 | |
urllib3.disable_warnings() | |
def test1(): | |
ip_list = [ | |
'1.1.1.1', | |
'2.2.2.1', | |
'3.3.3.1', | |
'4.4.4.1' | |
] | |
bishttp = True | |
# For https, remove www from the url | |
host_name = 'test.sample.com' | |
full_url = host_name+'' | |
headers = { | |
"Host": host_name, | |
"Accept-Encoding": 'br gzip' | |
} | |
for ip in ip_list: | |
print('Trying to access %s via IP: %s' %(host_name, ip)) | |
try: | |
if not bishttp: | |
response = requests.get("http://" + ip, headers=headers) | |
else: | |
session = requests.Session() | |
session.mount('https://'+full_url, ForcedIPHTTPSAdapter(dest_ip=ip)) | |
response = session.get('https://'+full_url, headers=headers, verify=False) | |
if response != '': | |
print('The headers:') | |
for key, value in sorted(response.headers.items()): | |
print('\t', key, value) | |
else: | |
print('\r\n') | |
except Exception as e: | |
print("%s\r\nFailed to Access %s" %(e, host_name, )) | |
if __name__ == '__main__': | |
test1() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment