我们在机房选择、測试网络的质量的时候,往往仅仅依据跳数、延迟、抖动、网络吞吐量等指标来衡量,非常多时候跳数并不能全然显示网络拓扑优劣,于是写了个traceroute结合whois的小脚本来直观显示每一跳所处的网络位置。


须要安装mtr和whois


脚本:

[root@localhost ~]# more  geotrace.sh         

#!/bin/bash
echo traceroute ip:$1 from localhost
ip=$1
echo
#mtr --n --report $ip|grep -v ^HOST|awk '{printf $1" "$2" ";system("whois "$2"|grep descr|head -n1|cut -c17-");printf "\n"}'
mtr --n --report $ip|grep -v ^HOST|awk '{printf $1" "$2" ";system("whois "$2"|grep -e netname -e descr|cut -c17-");printf "\n"}
'


測试结果还挺令人惬意:

[root@localhost ~]# ./geotrace.sh 8.8.8.8

traceroute ip:8.8.8.8 from localhost

1. 210.14.148.129 SHUJUJIA
Beijing ShuJuJia Technology Co., Ltd.
Triumph 170 Kai Xuan Cheng, 26th Floor, Block C
Bei Yuan Road, Chaoyang District, Beijing City

2. ??? 
3. 172.17.2.1 
4. 61.49.39.25 UNICOM-BJ
China Unicom Beijing province network
China Unicom

5. 202.106.35.1 UNICOM-BJ
China Unicom Beijing province network
China Unicom

6. 61.148.155.161 UNICOM-BJ
China Unicom Beijing province network
China Unicom

7. 123.126.0.29 UNICOM-BJ
China Unicom Beijing province network
China Unicom

8. 219.158.101.118 CNCGROUP
CNC group
China Unicom IP Network

9. 219.158.3.218 ChinaUnicom-BACKBONE
Backbone of China Unicom
China Unicom IP Network

10. 219.158.96.198 CNCGROUP
CNC group
China Unicom IP Network

11. 219.158.25.142 ChinaUnicom-BACKBONE
Backbone of China Unicom
China Unicom IP Network

12. 219.158.33.174 CNCGROUP-BACKBONE
Backbone of CNC group
CNC Group CHINA169 Backbone

13. 209.85.241.58 
14. 209.85.253.71 
15. ???

 
16. 8.8.8.8 
[root@localhost ~]#