Last active
July 14, 2021 04:55
-
-
Save yumusb/4b58878b18710c41878cad3f1f01a68b to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
red='\e[91m' | |
green='\e[92m' | |
yellow='\e[93m' | |
magenta='\e[95m' | |
cyan='\e[96m' | |
none='\e[0m' | |
#检查是否root用户 | |
[[ $(id -u) != 0 ]] && echo -e " 哎呀……请使用 ${red}root ${none}用户运行 ${yellow}~(^_^) ${none}" && exit 1 | |
#判断包管理类型 | |
if [[ $(command -v yum) ]]; then | |
cmd="yum" | |
elif [[ $(command -v apt) ]]; then | |
cmd="apt" | |
else | |
echo -e "暂不支持你的系统哦!" && exit 1 | |
fi | |
$cmd update -y | |
$cmd install curl -y | |
$cmd install traceroute -y | |
curl -s --connect-timeout 4 -m 10 http://ip-api.com/json/ | grep -q -i "China" | |
if [[ $? == 0 ]];then | |
curl -s --connect-timeout 4 -m 10 http://ip-api.com/json/ | grep -q -i "hk" | |
if [[ $? != 0 ]];then | |
echo | |
echo "中国大陆的服务器无需检测,不用看,肯定很优秀!!" | |
echo | |
exit; | |
fi | |
fi | |
echo -e "\n该小工具可以为你检查本服务器到中国北京、上海、广州的[回程网络]类型\n" | |
read -p "按Enter(回车)开始启动检查..." sdad | |
iplise=(219.141.136.10 202.106.196.115 211.136.28.231 202.96.199.132 211.95.72.1 211.136.112.50 61.144.56.100 211.95.193.97 120.196.122.69) | |
iplocal=(北京电信 北京联通 北京移动 上海电信 上海联通 上海移动 广州电信 广州联通 广州移动) | |
echo -e "\n正在测试,请骚等..." | |
echo -e "——————————————————————————————\n" | |
for i in {0..8}; do | |
traceroute ${iplise[i]} > /tmp/traceroute_testlog | |
grep -q "59.43" /tmp/traceroute_testlog | |
if [ $? == 0 ];then | |
#grep -q "202.97" /tmp/traceroute_testlog | |
#if [ $? == 0 ];then | |
# echo -e "目标:${iplocal[i]}[${iplise[i]}]\t回程线路:\033[1;32m电信CN2 GT\033[0m" | |
#else | |
# echo -e "目标:${iplocal[i]}[${iplise[i]}]\t回程线路:\033[1;31m电信CN2 GIA\033[0m" | |
#fi | |
echo -e "目标:${iplocal[i]}[${iplise[i]}]\t回程线路:\033[1;31m电信CN2 GIA\033[0m" | |
else | |
grep -q "202.97" /tmp/traceroute_testlog | |
if [ $? == 0 ];then | |
echo -e "目标:${iplocal[i]}[${iplise[i]}]\t回程线路:\033[1;34m电信163\033[0m" | |
else | |
grep -q "219.158" /tmp/traceroute_testlog | |
if [ $? == 0 ];then | |
echo -e "目标:${iplocal[i]}[${iplise[i]}]\t回程线路:\033[1;33m联通169\033[0m" | |
else | |
grep -q "223.120" /tmp/traceroute_testlog | |
if [ $? == 0 ];then | |
echo -e "目标:${iplocal[i]}[${iplise[i]}]\t回程线路:\033[1;35m移动CMI\033[0m" | |
else | |
grep -q "221.183" /tmp/traceroute_testlog | |
if [ $? == 0 ];then | |
echo -e "目标:${iplocal[i]}[${iplise[i]}]\t回程线路:\033[1;35m移动cmi\033[0m" | |
else | |
echo -e "目标:${iplocal[i]}[${iplise[i]}]\t回程线路:其他" | |
fi | |
fi | |
fi | |
fi | |
fi | |
echo | |
done | |
rm -rf /tmp/traceroute_testlog | |
echo -e "\n——————————————————————————————\n测试结果 仅供参考\n" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment