VPS 路由测试脚本
因为众所周知,我这个人极其懒,所以 VPS 路由测试这种事情怎么能让我手动干呢,因此就有了这个脚本。
为什么需要知道VPS路由
主要可以拿来评测VPS的线路质量。
脚本本体
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84
|
#!/usr/bin/env bash
## 路由追踪模组
set +e
## 安装traceroute apt-get -y install traceroute
## 路由ASN routes=(AS4134 AS4837 AS9808 AS4538 AS4809 AS9929 AS2914 AS2497 AS2516 AS4725 AS3491 AS9269 AS4635 AS4760 AS58453 AS4637 AS64050 AS6939 AS174 AS3356 AS3257 AS6461 AS701 AS7018 AS1239 AS1299 AS6453 AS6830 AS5511 AS6762 AS3320)
## ASN对应的ISP名称 routes_name=(163 169 CMNET CERNET CN2 CU-VIP NTT IIJ KDDI SoftBank PCCW HKBN HKIX HKT CMI Telstra BGPNET HE Cogent LEVEL3 GTT Zayo Verizon ATT T-Mobile Arelion TATA Liberty Orange SPARKLE Deutsche)
## 路由测试目的地IP(对应电信,联通,移动) ct_ip="116.228.111.118" cu_ip="210.22.70.3" cm_ip="211.136.112.50"
## 使用ipinfo.io获取ip对应的ASN ipinfo_token="56c375418c62c9"
route_test(){
TERM=ansi whiptail --title "路由测试" --infobox "路由测试,请耐心等待。" 7 68
## 测试路由并汇总结果 traceroute ${ct_ip} -n -T -m 20 | tail -n +2 &> route_all.txt traceroute ${cu_ip} -n -T -m 20 | tail -n +2 &>> route_all.txt traceroute ${cm_ip} -n -T -m 20 | tail -n +2 &>> route_all.txt
ips=() asns=() route_vps=()
## 过滤出IP while IFS="" read -r p || [ -n "$p" ] do ip=$(printf '%s\n' "$p" | cut -d' ' -f4) if [[ $ip =~ ^[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+$ ]]; then ips+=( $ip ) fi done < route_all.txt
## 获取IP对应的ASN for ip in "${ips[@]}"; do asns+=($(curl --retry 5 -s https://ipinfo.io/${ip}/org?token=${ipinfo_token} --connect-timeout 300 | cut -d' ' -f1 )) if [[ $ip = 59.43* ]] ; then route_vps+=(AS4809) fi done
## 与预定义列表比对,找出路由相关ASN for asn in "${asns[@]}"; do for route in "${routes[@]}"; do if echo "$asn" | grep -q "$route"; then route_vps+=($route) fi done done
rm route_all.txt rm route.txt &> /dev/null
## 将ASN映射为预定义的ISP名称 for i in "${!route_vps[@]}"; do for o in "${!routes[@]}"; do if [[ "${route_vps[$i]}" == "${routes[$o]}" ]]; then echo "${routes_name[$o]}" >> route.txt fi done done
## 结果去重 route_final=$(cat route.txt | sort | uniq | tr '\n' ' ')
## 输出结果 echo $route_final
rm route.txt } ## 执行测试 route_test
|
使用方法
下载脚本并执行
1 2 3
|
curl --retry 5 -LO https://raw.githubusercontent.com/johnrosen1/vpstoolbox/master/install/route.sh source route.sh route_test
|
等待输出结果
总结
有这个脚本,我总算可以知道我随手买的垃圾 VPS 是什么垃圾了,2333。
本文转自: https://johnrosen1.com/2022/04/18/route/
本站仅做收录,版权归原作者所有。