From eebdd893f404108ddaee1d5e16e32c99cd7231a4 Mon Sep 17 00:00:00 2001 From: Dnomd343 Date: Fri, 12 Mar 2021 16:29:05 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E8=87=AA=E5=8A=A8=E8=BF=9E=E6=8E=A5?= =?UTF-8?q?=E4=B8=AD=E5=9B=BD=E8=8A=82=E7=82=B9=E6=B5=8B=E9=80=9F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- cn.sh | 227 +++++++++++++++++++++++++++++++++++++++++++++++++++ list/ALL.dat | 33 ++++++++ list/DX.dat | 18 ++++ list/LT.dat | 23 ++++++ list/YD.dat | 48 +++++++++++ 5 files changed, 349 insertions(+) create mode 100644 cn.sh create mode 100644 list/ALL.dat create mode 100644 list/DX.dat create mode 100644 list/LT.dat create mode 100644 list/YD.dat diff --git a/cn.sh b/cn.sh new file mode 100644 index 0000000..cc675a7 --- /dev/null +++ b/cn.sh @@ -0,0 +1,227 @@ +#!/usr/bin/env bash + +RED='\033[0;31m' +GREEN='\033[0;32m' +YELLOW='\033[0;33m' +BLUE='\033[0;34m' +PURPLE="\033[0;35m" +CYAN='\033[0;36m' +PLAIN='\033[0m' + +check_root(){ + [[ $EUID -ne 0 ]] && echo -e "${RED}请切换为root用户执行${PLAIN}" && exit 1 +} + +check_system() { + if [ -f /etc/redhat-release ]; then + package_type="RPM" + elif cat /etc/issue | grep -Eqi "debian"; then + package_type="DEB" + elif cat /etc/issue | grep -Eqi "ubuntu"; then + package_type="DEB" + elif cat /etc/issue | grep -Eqi "centos|red hat|redhat"; then + package_type="RPM" + elif cat /proc/version | grep -Eqi "debian"; then + package_type="DEB" + elif cat /proc/version | grep -Eqi "ubuntu"; then + package_type="DEB" + elif cat /proc/version | grep -Eqi "centos|red hat|redhat"; then + package_type="RPM" + fi +} + +python_setup() { + [[ -e '/usr/bin/python' ]] && return + echo -e "正在安装Python...\c" + if [ "${package_type}" == "RPM" ]; then + yum update > /dev/null 2>&1 + yum -y install python > /dev/null 2>&1 + else + apt-get update > /dev/null 2>&1 + apt-get -y install python > /dev/null 2>&1 + fi + if [ -e '/usr/bin/python' ]; then + echo -e "${GREEN}OK${PLAIN}" + else + echo -e "${RED}ERROR${PLAIN}" + exit 1 + fi +} + +curl_setup() { + [[ -e '/usr/bin/curl' ]] && return + echo -e "正在安装Curl...\c" + if [ "${package_type}" == "RPM" ]; then + yum update > /dev/null 2>&1 + yum -y install curl > /dev/null 2>&1 + else + apt-get update > /dev/null 2>&1 + apt-get -y install curl > /dev/null 2>&1 + fi + if [ -e '/usr/bin/curl' ]; then + echo -e "${GREEN}OK${PLAIN}" + else + echo -e "${RED}ERROR${PLAIN}" + exit 1 + fi +} + +wget_setup() { + [[ -e '/usr/bin/wget' ]] && return + echo -e "正在安装Wget...\c" + if [ "${package_type}" == "RPM" ]; then + yum update > /dev/null 2>&1 + yum -y install wget > /dev/null 2>&1 + else + apt-get update > /dev/null 2>&1 + apt-get -y install wget > /dev/null 2>&1 + fi + if [ -e '/usr/bin/wget' ]; then + echo -e "${GREEN}OK${PLAIN}" + else + echo -e "${RED}ERROR${PLAIN}" + exit 1 + fi +} + +speedtest_setup() { + [[ -e './st-temp/speedtest' ]] && return + echo -e "正在获取Speedtest-cli...\c" + mkdir -p ./st-temp/speedtest-cli + wget --no-check-certificate -qO ./st-temp/speedtest.tgz https://bintray.com/ookla/download/download_file?file_path=ookla-speedtest-1.0.0-$(uname -m)-linux.tgz > /dev/null 2>&1 + tar zxvf ./st-temp/speedtest.tgz -C ./st-temp/speedtest-cli/ > /dev/null 2>&1 + mv ./st-temp/speedtest-cli/speedtest ./st-temp/speedtest-cli/speedtest.5 ./st-temp/ + chmod a+rx ./st-temp/speedtest + rm -rf ./st-temp/speedtest.tgz ./st-temp/speedtest-cli + if [ -e './st-temp/speedtest' ]; then + echo -e "${GREEN}OK${PLAIN}" + else + echo -e "${RED}ERROR${PLAIN}" + clear_env + exit 1 + fi +} + +get_server() { + echo -e "正在获取服务器列表...\c" + rm -f ./st-temp/ALL.dat + rm -f ./st-temp/DX.dat + rm -f ./st-temp/LT.dat + rm -f ./st-temp/YD.dat + wget -P ./st-temp/ https://st.343.re/cn/ALL.dat > /dev/null 2>&1 + wget -P ./st-temp/ https://st.343.re/cn/DX.dat > /dev/null 2>&1 + wget -P ./st-temp/ https://st.343.re/cn/LT.dat > /dev/null 2>&1 + wget -P ./st-temp/ https://st.343.re/cn/YD.dat > /dev/null 2>&1 + [[ ! -e './st-temp/ALL.dat' ]] && echo -e "${RED}ERROR${PLAIN}" && clear_env && exit 1 + [[ ! -e './st-temp/DX.dat' ]] && echo -e "${RED}ERROR${PLAIN}" && clear_env && exit 1 + [[ ! -e './st-temp/LT.dat' ]] && echo -e "${RED}ERROR${PLAIN}" && clear_env && exit 1 + [[ ! -e './st-temp/YD.dat' ]] && echo -e "${RED}ERROR${PLAIN}" && clear_env && exit 1 + echo -e "${GREEN}OK${PLAIN}" +} + +load_server() { + local dat + while read temp_line + do + dat=(${temp_line//,/ }) + id_arr[${#id_arr[@]}+1]=${dat[0]} + addr_arr[${#addr_arr[@]}+1]=${dat[1]} + isp_arr[${#isp_arr[@]}+1]=${dat[2]} + done <<< "$(cat $1)" + server_num=${#id_arr[@]} +} + +select_isp() { + echo -e "${GREEN}1.${PLAIN} 三网测速" + echo -e "${GREEN}2.${PLAIN} 电信节点" + echo -e "${GREEN}3.${PLAIN} 联通节点" + echo -e "${GREEN}4.${PLAIN} 移动节点" + echo -e "${GREEN}5.${PLAIN} 取消测速\c" + while :; do echo + read -p "请选择: " selection + if [[ ! $selection =~ ^[1-5]$ ]]; then + echo -e "${RED}输入无效${PLAIN}\c" + else + break + fi + done + [[ ${selection} == 5 ]] && clear_env && exit 1 + [[ ${selection} == 1 ]] && load_server './st-temp/ALL.dat' + [[ ${selection} == 2 ]] && load_server './st-temp/DX.dat' + [[ ${selection} == 3 ]] && load_server './st-temp/LT.dat' + [[ ${selection} == 4 ]] && load_server './st-temp/YD.dat' +} + +speedtest() { + speedLog="./st-temp/speedtest.log" + touch $speedLog + ./st-temp/speedtest -p no -s $1 --accept-license > $speedLog 2>&1 + echo -en "\r" + echo -en " " + echo -en "\r" + is_upload=$(cat $speedLog | grep 'Upload') + if [[ ${is_upload} ]]; then + local REDownload=$(cat $speedLog | awk -F ' ' '/Download/{print $3}') + local reupload=$(cat $speedLog | awk -F ' ' '/Upload/{print $3}') + local relatency=$(cat $speedLog | awk -F ' ' '/Latency/{print $2}') + local nodeID=$1 + local nodeLocation=$2 + local nodeISP=$3 + strnodeLocation="${nodeLocation}      " + LANG=C + temp=$(echo "${REDownload}" | awk -F ' ' '{print $1}') + if [[ $(awk -v num1=${temp} -v num2=0 'BEGIN{print(num1>num2)?"1":"0"}') -eq 1 ]]; then + printf "${RED}%-6s${YELLOW}%s%s${GREEN}%-24s${CYAN}%s%-10s${BLUE}%s%-10s${PURPLE}%-8s${PLAIN}\n" "${nodeID}" "${nodeISP}" "|" "${strnodeLocation:0:24}" "↑ " "${reupload}" "↓ " "${REDownload}" "${relatency}" | tee -a $log + fi + else + local cerror="ERROR" + fi +} + +runtest() { + echo -en "\033[?25l" + echo "——————————————————————————————————————————————————————————" + curl "ip.343.re/info" + echo "——————————————————————————————————————————————————————————" + echo "ID 测速服务器信息 上传/Mbps 下载/Mbps 延迟/ms" + start=$(date +%s) + for ((i=1;i<=$server_num;i++)) do + echo -e "正在测试 ${YELLOW}${isp_arr[i]}|${PLAIN}${GREEN}${addr_arr[i]}${PLAIN} ...\c" + speedtest ${id_arr[i]} ${addr_arr[i]} ${isp_arr[i]} + done + end=$(date +%s) + echo "——————————————————————————————————————————————————————————" + time=$(( $end - $start )) + if [[ $time -gt 60 ]]; then + min=$(expr $time / 60) + sec=$(expr $time % 60) + echo -e "测试完成, 共耗时${CYAN} ${min} 分 ${sec} 秒${PLAIN}" + else + echo -e "测试完成, 共耗时${CYAN} ${time} 秒${PLAIN}" + fi + echo -e "\033[?25h" +} + +clear_env() { + rm -rf ./st-temp +} + +init() { + check_root + check_system + python_setup + curl_setup + wget_setup + speedtest_setup + get_server +} + +main() { + init + select_isp + clear + runtest + clear_env +} + +main diff --git a/list/ALL.dat b/list/ALL.dat new file mode 100644 index 0000000..ff83049 --- /dev/null +++ b/list/ALL.dat @@ -0,0 +1,33 @@ +3633,上海,电信 +24012,内蒙古呼和浩特,电信 +27377,北京5G,电信 +29026,四川成都,电信 +17145,安徽合肥5G,电信 +27594,广东广州5G,电信 +27575,新疆乌鲁木齐,电信 +5396,江苏苏州5G,电信 +23844,湖北武汉,电信 +29353,湖北武汉5G,电信 +28225,湖南长沙5G,电信 +3973,甘肃兰州,电信 +24447,上海5G,联通 +5145,北京,联通 +2461,四川成都,联通 +27154,天津5G,联通 +26180,山东济南5G,联通 +26678,广东广州5G,联通 +13704,江苏南京,联通 +5485,湖北武汉,联通 +4870,湖南长沙,联通 +4863,陕西西安,联通 +30232,内蒙呼和浩特5G,移动 +25858,北京,移动 +16375,吉林长春,移动 +17184,天津5G,移动 +27151,山东临沂5G,移动 +31520,广东中山,移动 +26938,新疆乌鲁木齐5G,移动 +25883,江西南昌5G,移动 +16171,福建福州,移动 +16398,贵州贵阳,移动 +25728,辽宁大连,移动 \ No newline at end of file diff --git a/list/DX.dat b/list/DX.dat new file mode 100644 index 0000000..352ca4f --- /dev/null +++ b/list/DX.dat @@ -0,0 +1,18 @@ +3633,上海,电信 +24012,内蒙古呼和浩特,电信 +27377,北京5G,电信 +29026,四川成都,电信 +29071,四川成都,电信 +17145,安徽合肥5G,电信 +27594,广东广州5G,电信 +27810,广西南宁,电信 +27575,新疆乌鲁木齐,电信 +26352,江苏南京5G,电信 +5396,江苏苏州5G,电信 +5317,江苏连云港5G,电信 +7509,浙江杭州,电信 +23844,湖北武汉,电信 +29353,湖北武汉5G,电信 +28225,湖南长沙5G,电信 +3973,甘肃兰州,电信 +19076,重庆,电信 \ No newline at end of file diff --git a/list/LT.dat b/list/LT.dat new file mode 100644 index 0000000..03402d3 --- /dev/null +++ b/list/LT.dat @@ -0,0 +1,23 @@ +21005,上海,联通 +24447,上海5G,联通 +5103,云南昆明,联通 +5145,北京,联通 +5505,北京,联通 +9484,吉林长春,联通 +2461,四川成都,联通 +27154,天津5G,联通 +5509,宁夏银川,联通 +5724,安徽合肥,联通 +5039,山东济南,联通 +26180,山东济南5G,联通 +26678,广东广州5G,联通 +16192,广东深圳,联通 +6144,新疆乌鲁木齐,联通 +13704,江苏南京,联通 +5485,湖北武汉,联通 +26677,湖南株洲,联通 +4870,湖南长沙,联通 +4690,甘肃兰州,联通 +4884,福建福州,联通 +31985,重庆,联通 +4863,陕西西安,联通 \ No newline at end of file diff --git a/list/YD.dat b/list/YD.dat new file mode 100644 index 0000000..3d8f232 --- /dev/null +++ b/list/YD.dat @@ -0,0 +1,48 @@ +30154,上海,移动 +25637,上海5G,移动 +26728,云南昆明,移动 +27019,内蒙古呼和浩特,移动 +30232,内蒙呼和浩特5G,移动 +30293,内蒙古通辽5G,移动 +25858,北京,移动 +16375,吉林长春,移动 +24337,四川成都,移动 +17184,天津5G,移动 +26940,宁夏银川,移动 +31815,宁夏银川,移动 +26404,安徽合肥5G,移动 +27151,山东临沂5G,移动 +25881,山东济南5G,移动 +27100,山东青岛5G,移动 +26501,山西太原5G,移动 +31520,广东中山,移动 +6611,广东广州,移动 +4515,广东深圳,移动 +15863,广西南宁,移动 +16858,新疆乌鲁木齐,移动 +26938,新疆乌鲁木齐5G,移动 +17227,新疆和田,移动 +17245,新疆喀什,移动 +17222,新疆阿勒泰,移动 +27249,江苏南京5G,移动 +21845,江苏常州5G,移动 +26850,江苏无锡5G,移动 +17320,江苏镇江5G,移动 +25883,江西南昌5G,移动 +17223,河北石家庄,移动 +26331,河南郑州5G,移动 +6715,浙江宁波5G,移动 +4647,浙江杭州,移动 +16503,海南海口,移动 +28491,湖南长沙5G,移动 +16145,甘肃兰州,移动 +16171,福建福州,移动 +18444,西藏拉萨,移动 +16398,贵州贵阳,移动 +25728,辽宁大连,移动 +16167,辽宁沈阳,移动 +17584,重庆,移动 +26380,陕西西安,移动 +29105,陕西西安5G,移动 +29083,青海西宁5G,移动 +26656,黑龙江哈尔滨,移动 \ No newline at end of file