External IP Fix
@@ -74,27 +74,47 @@ def get_external_ip() -> str:
# --- Try curl.
try:
external_ip = os.popen('curl -s ifconfig.me').readline()
+ assert isinstance(ip_to_int(external_ip), int)
return str(external_ip)
except:
pass
- # --- Try urllib
+ # --- Try ipify
try:
- external_ip = urllib.request.urlopen('https://ident.me').read().decode('utf8')
+ external_ip = requests.get('https://api.ipify.org').text
+ assert isinstance(ip_to_int(external_ip), int)
return str(external_ip)
except:
pass
- # --- Try ipify
+ # --- Try AWS
try:
- external_ip = requests.get('https://api.ipify.org').text
+ external_ip = requests.get('https://checkip.amazonaws.com').text.strip()
+ assert isinstance(ip_to_int(external_ip), int)
return str(external_ip)
except:
pass
- # --- Try AWS
+ # --- Try myip.dnsomatic
try:
- external_ip = requests.get('https://checkip.amazonaws.com').text.strip()
+ external_ip = os.popen('curl -s myip.dnsomatic.com').readline()
+ assert isinstance(ip_to_int(external_ip), int)
+ return str(external_ip)
+ except:
+ pass
+
+ # --- Try urllib ipv6 (Doesn't work yet)
+ try:
+ external_ip = urllib.request.urlopen('https://ident.me').read().decode('utf8')
+ assert isinstance(ip_to_int(external_ip), int)
+ return str(external_ip)
+ except:
+ pass
+
+ # --- Try Wikipedia ipv6 (Doesn't work yet)
+ try:
+ external_ip = requests.get('https://www.wikipedia.org').headers['X-Client-IP']
+ assert isinstance(ip_to_int(external_ip), int)
return str(external_ip)
except:
pass
