Merge pull request #28 from wloot/patch-1
Use 1.1.1.1 api instead of dirty hack to get ip
This commit is contained in:
commit
1235464e18
@ -1,5 +1,3 @@
|
|||||||
import socket
|
|
||||||
import requests.packages.urllib3.util.connection as urllib3_cn
|
|
||||||
import requests, json, sys, os
|
import requests, json, sys, os
|
||||||
import time
|
import time
|
||||||
|
|
||||||
@ -12,40 +10,19 @@ if(version < 3.5):
|
|||||||
with open(PATH + "config.json") as config_file:
|
with open(PATH + "config.json") as config_file:
|
||||||
config = json.loads(config_file.read())
|
config = json.loads(config_file.read())
|
||||||
|
|
||||||
def allowed_gai_family6():
|
|
||||||
family = socket.AF_INET
|
|
||||||
if urllib3_cn.HAS_IPV6:
|
|
||||||
family = socket.AF_INET6 # force ipv6 only if it is available
|
|
||||||
return family
|
|
||||||
|
|
||||||
def allowed_gai_family4():
|
|
||||||
family = socket.AF_INET
|
|
||||||
return family
|
|
||||||
|
|
||||||
def getIPs():
|
def getIPs():
|
||||||
a = ""
|
a = ""
|
||||||
aaaa = ""
|
aaaa = ""
|
||||||
try:
|
try:
|
||||||
urllib3_cn.allowed_gai_family = allowed_gai_family4
|
a = requests.get("https://1.1.1.1/cdn-cgi/trace").text.split("\n")
|
||||||
a = requests.get("https://www.cloudflare.com/cdn-cgi/trace").text.split("\n")
|
|
||||||
a.pop()
|
a.pop()
|
||||||
ajson = json.loads("{}")
|
a = dict(s.split("=") for s in a)["ip"]
|
||||||
for value in a:
|
except Exception:
|
||||||
value = value.split("=")
|
|
||||||
ajson[value[0]] = value[1]
|
|
||||||
a = ajson['ip']
|
|
||||||
except Exception as e:
|
|
||||||
print(e)
|
|
||||||
print("Warning: IPv4 not detected.")
|
print("Warning: IPv4 not detected.")
|
||||||
try:
|
try:
|
||||||
urllib3_cn.allowed_gai_family = allowed_gai_family6
|
aaaa = requests.get("https://[2606:4700:4700::1111]/cdn-cgi/trace").text.split("\n")
|
||||||
aaaa = requests.get("https://www.cloudflare.com/cdn-cgi/trace").text.split("\n")
|
|
||||||
aaaa.pop()
|
aaaa.pop()
|
||||||
aaaajson = json.loads("{}")
|
aaaa = dict(s.split("=") for s in aaaa)["ip"]
|
||||||
for value in aaaa:
|
|
||||||
value = value.split("=")
|
|
||||||
aaaajson[value[0]] = value[1]
|
|
||||||
aaaa = aaaajson['ip']
|
|
||||||
except Exception:
|
except Exception:
|
||||||
print("Warning: IPv6 not detected.")
|
print("Warning: IPv6 not detected.")
|
||||||
ips = []
|
ips = []
|
||||||
|
|||||||
Reference in New Issue
Block a user