This commit is contained in:
yumoqing 2023-08-19 18:35:52 +08:00
parent 1801a8d467
commit d6f9c636fd

View File

@ -119,9 +119,9 @@ class IPgetter(object):
random.shuffle(self.server_list) random.shuffle(self.server_list)
myip = '' myip = ''
for server in self.server_list[:3]: for server in self.server_list:
myip = self.fetch(server) myip = self.defaultparser(self.fetch(server))
if myip != '': if myip != '' and not (myip.startswith('192.') or myip.startswith('10.')) and not myip.startswith('127'):
return myip return myip
else: else:
continue continue
@ -135,13 +135,14 @@ class IPgetter(object):
p = '(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(' p = '(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.('
p += '25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[' p += '25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|['
p += '01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)' p += '01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)'
m = re.search( try:
p, m = re.search(p, content)
content) myip = m.group(0)
myip = m.group(0) if len(myip) > 0:
if len(myip) > 0: return myip
return myip else:
else: return ''
except:
return '' return ''
def handle_timeout(self, url): def handle_timeout(self, url):
@ -235,9 +236,4 @@ if __name__ == '__main__':
g = IPgetter() g = IPgetter()
server = 'http://ipinfo.io/json' server = 'http://ipinfo.io/json'
g.add_server(server, p) g.add_server(server, p)
print(g.fetch(server)) print(g.get_external_ip())
"""
while True:
print(myip())
time.sleep(0.5)
"""