Skip to content

Commit e6f1a0b

Browse files
committed
API Changed
1 parent 0e68814 commit e6f1a0b

File tree

1 file changed

+8
-5
lines changed

1 file changed

+8
-5
lines changed

main.py

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
1+
import re
12
import time
2-
import threading
33
import json
4+
import threading
45

56
import requests
67

@@ -14,8 +15,8 @@ def __init__(self,
1415
id, secret,
1516
sleep = 600,
1617
ipv4 = True, ipv6 = True,
17-
v4api = "https://ipv4.gh.ink",
18-
v6api = "https://ipv6.gh.ink"):
18+
v4api = "http://ipv4.ipv6-test.ch/ip/",
19+
v6api = "http://ipv6.ipv6-test.ch/ip"):
1920

2021
assert domain.count(".") == 1 and \
2122
not domain.startswith(".") and \
@@ -28,6 +29,8 @@ def __init__(self,
2829
self.ipv6 = ipv6
2930
self.v4api = v4api
3031
self.v6api = v6api
32+
self.v4re = re.compile(r"(((\d{1,2})|(1\d{2})|(2[0-4]\d)|(25[0-5]))\.){3}((\d{1,2})|(1\d{2})|(2[0-4]\d)|(25[0-5]))")
33+
self.v6re = re.compile(r"(([0-9a-fA-F]{1,4}:){7,7}[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,7}:|([0-9a-fA-F]{1,4}:){1,6}:[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,5}(:[0-9a-fA-F]{1,4}){1,2}|([0-9a-fA-F]{1,4}:){1,4}(:[0-9a-fA-F]{1,4}){1,3}|([0-9a-fA-F]{1,4}:){1,3}(:[0-9a-fA-F]{1,4}){1,4}|([0-9a-fA-F]{1,4}:){1,2}(:[0-9a-fA-F]{1,4}){1,5}|[0-9a-fA-F]{1,4}:((:[0-9a-fA-F]{1,4}){1,6})|:((:[0-9a-fA-F]{1,4}){1,7}|:)|fe80:(:[0-9a-fA-F]{0,4}){0,4}%[0-9a-zA-Z]{1,}|::(ffff(:0{1,4}){0,1}:){0,1}((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\.){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])|([0-9a-fA-F]{1,4}:){1,4}:((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\.){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9]))")
3134

3235
self.__client = AcsClient(id, secret, 'cn-hangzhou')
3336

@@ -44,7 +47,7 @@ def refresh(self):
4447
# Get local public ipv4 address
4548
if self.ipv4:
4649
try:
47-
self.__v4 = requests.get(self.v4api).text
50+
self.__v4 = re.search(self.v4re, requests.get(self.v4api).text).group(0)
4851
except Exception as e:
4952
print("Failed to get local public ipv4 address,", e)
5053
else:
@@ -83,7 +86,7 @@ def refresh(self):
8386
# Get local public ipv6 address
8487
if self.ipv6:
8588
try:
86-
self.__v6 = requests.get(self.v6api).text
89+
self.__v6 = re.search(self.v6re, requests.get(self.v6api).text).group(0)
8790
except Exception as e:
8891
print("Failed to get local public ipv6 address,", e)
8992
else:

0 commit comments

Comments
 (0)