Skip to content

Commit d336201

Browse files
committed
add 2nd way to get own ip
1 parent 2736c57 commit d336201

File tree

1 file changed

+6
-0
lines changed

1 file changed

+6
-0
lines changed

mytoninstaller/config.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import os
22
import json
3+
import re
34
import subprocess
45
import requests
56
import base64
@@ -118,8 +119,13 @@ def CreateLocalConfig(local, initBlock, localConfigPath=defaultLocalConfigPath):
118119

119120

120121
def get_own_ip():
122+
pat = re.compile(r"^((25[0-5]|(2[0-4]|1\d|[1-9]|)\d)(\.(?!$)|$)){4}$")
121123
requests.packages.urllib3.util.connection.HAS_IPV6 = False
122124
ip = requests.get("https://ifconfig.me/ip").text
125+
if not pat.fullmatch(ip):
126+
ip = requests.get("https://ipinfo.io/ip").text
127+
if not pat.fullmatch(ip):
128+
raise Exception('Cannot get own IP address')
123129
return ip
124130
#end define
125131

0 commit comments

Comments
 (0)