VPS Routing Test Script

VPS Routing Test Script

Because as we all know, I am extremely lazy, so how can I do things like VPS routing test manually, so I have this script.


Why you need to know VPS routing

It can mainly be used to evaluate the line quality of VPS.

script body

 1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
twenty one
twenty two
twenty three
twenty four
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

## route tracking module

set +e

## install traceroute
apt-get -y install traceroute

## Routing 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)

## ISP name corresponding to ASN
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)

## Routing test destination IP (corresponding to China Telecom, China Unicom, China Mobile)
ct_ip= "116.228.111.118"
cu_ip= "210.22.70.3"
cm_ip= "211.136.112.50"

## Use ipinfo.io to get the ASN corresponding to ip
ipinfo_token= "56c375418c62c9"

route_test (){

TERM=ansi whiptail --title "Route test" --infobox "Route test, please be patient." 7 68

## Test the route and summarize the results
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=()

## filter out IP
while IFS= "" read -rp || [ -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

## Get the ASN corresponding to the IP
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

## Compare with the predefined list to find out the ASN related to the route
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

## Map ASN to predefined ISP name
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

## result deduplication
route_final=$( cat route.txt | sort | uniq | tr '\n' ' ' )

## output result
echo $route_final

rm route.txt
}
## execute the test
route_test

Instructions

Download the script and execute it

 1
2
3
 curl --retry 5 -LO https://raw.githubusercontent.com/johnrosen1/vpstoolbox/master/install/route.sh
source route.sh
route_test

wait for output

 1
2
 169 CMNET IIJ Telstra
root@cloud:~ #

Summarize

With this script, I can finally know what the garbage VPS I bought is garbage, 2333.

This article is reprinted from: https://johnrosen1.com/2022/04/18/route/
This site is for inclusion only, and the copyright belongs to the original author.

Leave a Comment