Coder Social home page Coder Social logo

akamtester's Introduction

akamTester

批量测试B站海外CDN(upos-hz-mirrorakam.akamaized.net)节点延迟,找出最低延迟的节点。

在之后在Hosts中追加:

最低延迟的IP upos-hz-mirrorakam.akamaized.net

另外, ip_list.txt 文件用于保存解析出来的ip列表, 当正常解析完成时, 该文件会刷新, 当解析失败时, 会读取该文件中的ip列表。

⚠️ 在Win7上需要使用管理员权限运行! ⚠️

EXE文件运行

不熟悉Python的用户从 releases 下载exe文件直接使用。

源码运行

安装依赖:

For Windows cmd:

pip3 install requests beautifulsoup4 lxml termcolor pythonping dnspython

For Linux (tested on Arch Linux):

sudo pip install -r requirements.txt

执行 akamTester.py

python3 akamTester.py

指定测试域名

从v3.2开始, 用户可以通过-u参数指定测试域名.

举例:

python3 akamTester.py -u upos-sz-mirrorks3.bilivideo.com

关于轮子

GlobalDNS

GlobalDNS 是个对域名进行全球解析的类, 使用 www.whatsmydns.net 的 API 进行解析,额外包含本地、谷歌、腾讯、阿里 DNS 的解析结果。

导入

from GlobalDNS import GlobalDNS

使用

akam = GlobalDNS('upos-hz-mirrorakam.akamaized.net')
ip_list = akam.get_ip_list()  # 取得全球解析结果, 返回一个 set
akam.renew()  # 重新解析
ip_list = akam.get_ip_list()  # 将返回最近一次全球解析的结果

ColorPrinter

ColorPrinter 染色输出工具, 可输出红绿及默认颜色(一般终端为白色), 可跨平台, 包括pyCharm中的运行窗口

导入

from ColorPrinter import color_print

使用

color_print('Hello World')  # 默认输出颜色
color_print('Hello World', status=1)  # 输出红色
color_print('Hello World', status=2)  # 输出绿色

akamtester's People

Contributors

dependabot[bot] avatar enshulv avatar kukat avatar lixian-zhang avatar miyouzi avatar xyq1113723547 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

akamtester's Issues

exe运行显示乱码

捕获

应该是中文显示的全是问号,是哪里语言的设置没有变成Unicode之类的原因吗?

[Feature] 关于ipv6的支持

作者您好,一些运营商已经提供了ipv6网络,请问能否考虑同时解析AAAA记录以支持ipv6呢?

运行源码 报错了

MacOS Mojave Platform

git下来 安装依赖,执行语句,后续报错了

(master)⚡ % python3 akamTester.py > akamtester_log.txt          ~/Desktop/akamTester
第一次解析:
正在对 upos-hz-mirrorakam.akamaized.net 进行全球解析……
upos-hz-mirrorakam.akamaized.net 的全球解析已完成

第二次解析:
正在对 upos-hz-mirrorakam.akamaized.net 进行全球解析……
upos-hz-mirrorakam.akamaized.net 的全球解析已完成

第三次解析:
正在对 upos-hz-mirrorakam.akamaized.net 进行全球解析……
upos-hz-mirrorakam.akamaized.net 的全球解析已完成

共取得 69 个 IP, 开始测试延迟

Traceback (most recent call last):
  File "akamTester.py", line 67, in <module>
    delay = ping_test(ip)
  File "akamTester.py", line 19, in ping_test
    result = ping(ip, count=5)
  File "/usr/local/lib/python3.7/site-packages/pythonping/__init__.py", line 52, in ping
    comm = executor.Communicator(target, provider, timeout, socket_options=options, verbose=verbose, output=out)
  File "/usr/local/lib/python3.7/site-packages/pythonping/executor.py", line 224, in __init__
    self.socket = network.Socket(target, 'icmp', source=None, options=socket_options)
  File "/usr/local/lib/python3.7/site-packages/pythonping/network.py", line 25, in __init__
    self.socket = socket.socket(socket.AF_INET, socket.SOCK_RAW, self.protocol)
  File "/usr/local/Cellar/python/3.7.4_1/Frameworks/Python.framework/Versions/3.7/lib/python3.7/socket.py", line 151, in __init__
    _socket.socket.__init__(self, family, type, proto, fileno)
PermissionError: [Errno 1] Operation not permitted
Exception ignored in: <function Socket.__del__ at 0x1044585f0>
Traceback (most recent call last):
  File "/usr/local/lib/python3.7/site-packages/pythonping/network.py", line 56, in __del__
    if self.socket:
AttributeError: 'Socket' object has no attribute 'socket'
Exception ignored in: <function Communicator.__del__ at 0x104492170>
Traceback (most recent call last):
  File "/usr/local/lib/python3.7/site-packages/pythonping/executor.py", line 233, in __del__
    if self.socket:
AttributeError: 'Communicator' object has no attribute 'socket'

进击的巨人最终季无法观看

debug: [解除B站区域限制 v8.0.3 (Tampermonkey)] run on: https://www.bilibili.com/bangumi/play/ss36297/
debug: window.playinfo
debug: XMLHttpRequest的描述符: {"writable":true,"enumerable":false,"configurable":true}
info: mode: default blocked_vip: server: https://www.biliplus.com upos_server: flv_prefer_ws: remove_pre_ad: enable_in_av: readyState: loading isLogin: true isLoginBiliBili: true
debug: playinfo get
debug: /pgc/player/web/playurl
debug: season_type: 1
info: player msg: 从代理服务器拉取视频地址中...
debug: retryUntil.ajaxBy$: undefined
debug: set jQuery -> function(a,b){return new e.fn.init(a,b,h)}
debug: injectAjax at: function(a,b){return new e.fn.init(a,b,h)}
debug: fetch https://api.bilibili.com/pgc/player/web/playurl?cid=266399593&avid=&bvid=BV1vi4y1c7Sg&qn=80&fourk=1&otype=json&requestFrom=bilibili-helper {"method":"get","credentials":"include"}
debug: /x/web-interface/nav {"uname":"月色半轩窗","isLogin":true,"level":4,"vipType":2,"vipStatus":1,"isFromReport":false}
debug: /pgc/player/web/playurl origin block: true {"code":-10403,"message":"抱歉您所使用的平台不可观看!"}
debug: retryUntil.ajaxBy$: function(a,b){return new e.fn.init(a,b,h)}
debug: ajax: https://www.biliplus.com/BPplayurl.php?cid=266399593&qn=80&type=&otype=json&fourk=1&bvid=BV1vi4y1c7Sg&ep_id=371362&fnver=0&fnval=80&session=94ee96177e13abfe083d025894c563e5&module=pgc&access_key=4166503cf6109aebbefd9c8c0cb8f8b1&platform=android&fnval=0
error: {"code":-412,"message":"请求被拦截","ttl":1,"data":null,"loginStatus":{"isLogin":true,"uname":"月色半轩窗","mid":433167128,"level":4,"vip_expire":1684684800000}}
info: player msg: {"name":"AjaxException","message":"服务器错误: {"code":-412,"message":"请求被拦截","ttl":1,"data":null,"loginStatus":{"isLogin":true,"uname":"月色半轩窗","mid":433167128,"level":4,"vip_expire":1684684800000}}","code":-412}
info: player msg: 尝试使用kghost的服务器拉取视频地址...
debug: retryUntil.ajaxBy$: function(a,b){return new e.fn.init(a,b,h)}
debug: ajax: //bilibili-cn-api.kghost.info/pgc/player/web/playurl?cid=266399593&qn=80&type=&otype=json&fourk=1&bvid=BV1vi4y1c7Sg&ep_id=371362&fnver=0&fnval=80&session=94ee96177e13abfe083d025894c563e5&module=bangumi&access_key=4166503cf6109aebbefd9c8c0cb8f8b1
debug: playinfo set
debug: set jQuery function(a,b){return new e.fn.init(a,b,h)} -> function i(t,a){return new i.fn.init(t,a,e)}
debug: injectAjax at: function i(t,a){return new i.fn.init(t,a,e)}
debug: playinfo get
debug: playinfo get
debug: playinfo get
debug: playinfo get
debug: playinfo get
debug: playinfo get
debug: playinfo get
debug: season_type: 1
debug: playurl add 'module=bangumi' param
info: player msg: 从代理服务器拉取视频地址中...
debug: retryUntil.ajaxBy$: function i(t,a){return new i.fn.init(t,a,e)}
debug: ajax: https://www.biliplus.com/BPplayurl.php?avid=undefined&cid=266399593&bvid=BV1vi4y1c7Sg&qn=80&type=&otype=json&ep_id=371362&fourk=1&fnver=0&fnval=80&session=3827b7c029f535b43ab902cbdee32b7e&module=pgc&balh_ajax=1&access_key=4166503cf6109aebbefd9c8c0cb8f8b1&platform=android&fnval=0
debug: fetch https://api.bilibili.com/pgc/player/web/playurl?cid=266399593&avid=undefined&bvid=BV1vi4y1c7Sg&qn=80&fourk=1&otype=json&requestFrom=bilibili-helper {"method":"get","credentials":"include"}
error: {"code":-412,"message":"请求被拦截","ttl":1,"data":null,"loginStatus":{"isLogin":true,"uname":"月色半轩窗","mid":433167128,"level":4,"vip_expire":1684684800000}}
info: player msg: {"name":"AjaxException","message":"服务器错误: {"code":-412,"message":"请求被拦截","ttl":1,"data":null,"loginStatus":{"isLogin":true,"uname":"月色半轩窗","mid":433167128,"level":4,"vip_expire":1684684800000}}","code":-412}
info: player msg: 尝试使用kghost的服务器拉取视频地址...
debug: retryUntil.ajaxBy$: function i(t,a){return new i.fn.init(t,a,e)}
debug: ajax: //bilibili-cn-api.kghost.info/pgc/player/web/playurl?avid=undefined&cid=266399593&bvid=BV1vi4y1c7Sg&qn=80&type=&otype=json&ep_id=371362&fourk=1&fnver=0&fnval=80&session=3827b7c029f535b43ab902cbdee32b7e&module=bangumi&balh_ajax=1&access_key=4166503cf6109aebbefd9c8c0cb8f8b1
debug: /x/web-interface/nav {"uname":"月色半轩窗","isLogin":true,"level":4,"vipType":2,"vipStatus":1,"isFromReport":false}
debug: fetch https://api.bilibili.com/pgc/player/web/playurl?cid=266399593&avid=&bvid=BV1vi4y1c7Sg&qn=&fourk=0&otype=json&requestFrom=bilibili-helper {"method":"get","credentials":"include"}
debug: userAgent Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/87.0.4280.88 Safari/537.36 Edg/87.0.664.60

作了一个对下载速度实测的工具,带 IP 列表

首先,哈哈,作者和我考虑的一致,从国内访问 b 站的海外 cdn 比国内的 cdn 的最低质量都要高不少

其次,这个 cdn 取到的 IP 可能不太全面,比如
https://www.17ce.com/site/resolveip/20200805_b283e480d67411ea8d1cdb50ba3ecec9:1.html
有 100 多个upos-hz-mirrorakam.akamaized.net IP ,用本作取到只有8个,排除地区重复的可能,也最好可以设置一个手动可以输入IP列表的方式。

另外,最好能加上下载速度测算更准确,也就是web访问某个资源的大小除以时间,比如,我这里延迟比较高的 184.28.218.97 实际反而是下载速度最高的 cdn IP 之一

测试延迟时报错

QQ截图20200301163358

当前akamTester版本: 4.0
第一次解析:
正在对 upos-hz-mirrorakam.akamaized.net 进行全球解析……
upos-hz-mirrorakam.akamaized.net 的全球解析已完成

第二次解析:
正在对 upos-hz-mirrorakam.akamaized.net 进行全球解析……
upos-hz-mirrorakam.akamaized.net 的全球解析已完成

第三次解析:
正在对 upos-hz-mirrorakam.akamaized.net 进行全球解析……
upos-hz-mirrorakam.akamaized.net 的全球解析已完成

共取得 64 个 IP, 开始测试延迟

Traceback (most recent call last):
File "akamTester.py", line 80, in
delay = ping_test(ip)
File "akamTester.py", line 20, in ping_test
result = ping(ip, count=5)
File "C:\Program Files (x86)\Python37-32\lib\site-packages\pythonping_init_.py", line 52, in ping
comm = executor.Communicator(target, provider, timeout, socket_options=options, verbose=verbose, output=out)
File "C:\Program Files (x86)\Python37-32\lib\site-packages\pythonping\executor.py", line 239, in init
self.socket = network.Socket(target, 'icmp', source=None, options=socket_options)
File "C:\Program Files (x86)\Python37-32\lib\site-packages\pythonping\network.py", line 22, in init
self.protocol = socket.getprotobyname(protocol)
OSError: protocol not found
Exception ignored in: <function Socket.del at 0x036C4780>
Traceback (most recent call last):
File "C:\Program Files (x86)\Python37-32\lib\site-packages\pythonping\network.py", line 60, in del
raise AttributeError("Attribute error because of failed socket init. Make sure you have the root privilege."
AttributeError: Attribute error because of failed socket init. Make sure you have the root privilege. This error may also be caused from DNS resolution problems.

运行源码 报错

20240621105345

执行画面如图
是少安装什么吗?
刚开始我以为是fish shell的问题,换成bash问题依旧
环境是wsl2的ubuntu

Python version: 3.8.10
System: win10_21h2

求更新

能不能更新一个upos-sz-mirrorcosov.bilivideo.com的版本啊

能否增加对结果进行导出?

因为习惯用批处理省去输入命令的功夫,但是由于批处理难以同时保持回显和导出,能否对结果进行排序并导出?这样我可以方便地在自己的批处理中直接增加写入至hosts的功能

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.