Created
January 27, 2023 13:44
-
-
Save Zeebrow/f387a78fb15f0e6e25dd18c24823563e to your computer and use it in GitHub Desktop.
compare popular public ip getter sites
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
#!/usr/bin/env python3 | |
from time import time | |
import threading | |
import urllib3 | |
timeout = urllib3.Timeout(total=5.0) # see note https://urllib3.readthedocs.io/en/stable/reference/urllib3.util.html#urllib3.util.Timeout | |
header = { 'Cache-Control': 'no-cache' } | |
http = urllib3.PoolManager(timeout=timeout) | |
def time_request(url): | |
t_start = time() | |
try: | |
r = http.request('GET', url, headers=header, ) | |
except: | |
print(url.ljust(40, '.'), end='') | |
print("ERROR") | |
return | |
print(url.ljust(40, '.'), end='') | |
print("{:.10f}s".format(float(time() - t_start)), end='\t') | |
print(r.data) | |
ipv4 = [ | |
"http://ifconfig.me", | |
"http://ipv4.icanhazip.com", | |
'http://api.ipify.org', | |
'http://ipv4.ident.me', | |
'http://checkip.amazonaws.com', | |
"https://ifconfig.me", | |
"https://ipv4.icanhazip.com", | |
'https://api.ipify.org', | |
'https://ipv4.ident.me', | |
'https://checkip.amazonaws.com', | |
] | |
ipv6 = [ | |
"http://ipv6.icanhazip.com", | |
'http://ipv6.ident.me', | |
"https://ipv6.icanhazip.com", | |
'https://ipv6.ident.me', | |
] | |
threads = [] | |
for url in ipv4: | |
threads.append(threading.Thread(target=time_request, args=(url, ))) | |
for url in ipv6: | |
threads.append(threading.Thread(target=time_request, args=(url, ))) | |
for t in threads: | |
t.start() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment