Skip to content

Commit

Permalink
修复对 www.whatsmydns.net 的适配
Browse files Browse the repository at this point in the history
  • Loading branch information
miyouzi committed Oct 18, 2020
1 parent 91e3795 commit a31e6de
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 24 deletions.
29 changes: 8 additions & 21 deletions GlobalDNS.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
# @File : GlobalDNS.py
# @Software: PyCharm

import requests, dns.resolver
import requests, dns.resolver, json
from bs4 import BeautifulSoup
import re, time, socket

Expand Down Expand Up @@ -34,10 +34,10 @@ def __init_header(self):
header = {
"Host": host,
"User-Agent": ua,
# "referer": ref,
"referer": ref,
"Accept": accept,
"Accept-Language": lang,
# "Accept-Encoding": accept_encoding,
"Accept-Encoding": accept_encoding,
"Connection": "keep-alive",
"Upgrade-Insecure-Requests": "1",
"Pragma": cache_control,
Expand All @@ -62,18 +62,12 @@ def __request(self, url):

def __get_src(self):
bf4 = self.__request('https://www.whatsmydns.net/#A/' + self.__domain)
# bf4 = self.__request('https://www.whatsmydns.net/')
self.__src = bf4

def __get_token(self):
token = self.__src.find('input', id='_token')
self.__token = token.get('value')

def __get_dns_id(self):
a = self.__src.find_all('tr')
for id in a:
self.__dns_id.add(id.get('data-id'))
# print(self.__dns_id)

def __extend_query(self):
# 本地解析
Expand Down Expand Up @@ -102,20 +96,15 @@ def __extend_query(self):

def __global_query(self):
for dns_id in self.__dns_id:
url = 'https://www.whatsmydns.net/api/check?server='+dns_id\
+'&type=A&query='+self.__domain\
+'&_token='+self.__token
# print(url)
url = 'https://www.whatsmydns.net/api/details?server='+dns_id\
+'&type=A&query='+self.__domain
try:
src = self.__request(url)
# print('src= ',src)
ips = str(src.contents[0])
ip = re.findall(r'\d+\.\d+\.\d+\.\d+', ips)
self.__ip_list = self.__ip_list | set(ip)
details = self.__request(url).json()
ip = details["data"][0]["response"]
self.__ip_list = self.__ip_list | set(ip) # set 并集
except IndexError:
pass
# 该 DNS 失效
# print(self.__ip_list)

def get_ip_list(self):

Expand All @@ -128,9 +117,7 @@ def renew(self):
print('正在对 ' + self.__domain + ' 进行全球解析……')
self.__session.cookies.clear()
self.__get_src()
self.__get_token()
self.__get_dns_id()
self.__global_query()
self.__extend_query()
print(self.__domain + ' 的全球解析已完成')

9 changes: 6 additions & 3 deletions akamTester.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
working_dir = os.path.dirname(os.path.realpath(__file__))
# working_dir = os.path.dirname(sys.executable) # 使用 pyinstaller 编译时,打开此项
ip_list_path = os.path.join(working_dir, 'ip_list.txt')
version = 4.0
version = 4.1


def ping_test(ip):
Expand Down Expand Up @@ -90,8 +90,11 @@ def ping_test(ip):
color_print(ip['ip'] + '\t平均延迟: ' + str(ip['delay']) + ' ms', status=2)
else:
ip_info.sort(key=lambda x:x['delay'])
color_print('本次测试未能找到延迟低于100ms的IP! 以下为延迟最低的 3 个节点', status=1)
for i in range(0,3):
num = len(ip_info) # 要显示的节点数
if num > 3: # 如果解析的节点数超过 3 个, 那么显示 3 个就行
num = 3
color_print('本次测试未能找到延迟低于100ms的IP! 以下为延迟最低的 ' + str(num) + ' 个节点', status=1)
for i in range(0,num):
color_print(ip_info[i]['ip'] + '\t平均延迟: ' + str(ip_info[i]['delay']) + ' ms')

print()
Expand Down

0 comments on commit a31e6de

Please sign in to comment.