diff --git a/README.md b/README.md index 0024efc..e010775 100644 --- a/README.md +++ b/README.md @@ -1,30 +1,22 @@ -# Some Linux scripts -## Superspeed.sh -- Description: Test your server's network with Speedtest to China -- Intro: https://www.oldking.net/305.html -- Copyright (C) 2018 Oldking - -```bash -Usage: +## Superspeed.sh[1](#脚注1) +使用全国各地三大运营商[2](#脚注2)的 speedtest 测速节点进行全面测速[3](#脚注3)。 -| No. | Bash Command -|----------|--------------------------------- -| 1 | wget https://raw.githubusercontent.com/oooldking/script/master/superspeed.sh -| 2 | chmod +x superspeed.sh -| 3 | ./superspeed.sh +## 使用方法 +``` +bash <(curl -Lso- https://git.io/superspeed) ``` -## Superbench.sh -- Description: Auto test download & I/O speed & network to China script -- Intro: https://www.oldking.net/350.html -- Copyright (C) 2018 Oldking -```bash -Usage: +## 节点列表 +[查看全部节点列表(更新日期:2020/04/09)](https://git.io/superspeedList) -| No. | Bash Command | -|----------|---------------------------------| -| 1 | wget -qO- https://raw.githubusercontent.com/oooldking/script/master/superbench.sh | bash | -| 2 | curl -Lso- https://raw.githubusercontent.com/oooldking/script/master/superbench.sh | bash | -``` - +## 截图 +![测速图](SuperSpeed.png) + +--- + +1: Modified from Oldking's script。 + +2: 仅包括中国大陆地区电信、联通、移动节点。 +3: 使用 [ookla](https://bintray.com/ookla/download/download_file?file_path=ookla-speedtest-1.0.0-x86_64-linux.tgz) 提供的测速程序 +。 diff --git a/ServerList.md b/ServerList.md new file mode 100644 index 0000000..fea03db --- /dev/null +++ b/ServerList.md @@ -0,0 +1,107 @@ +更新日期:2020/04/09 + +注:在“三网测速”中,为了避免三网测试数量不均以及测试时长过久,每部分并未采用所有节点,如果需要全部检测,可以选择三网单独检测。 + +电信: + +| 服务器ID | 运营商 | 位置 | +| ----- | ---- | -------------- | +| 3633 | 电信 | 上海 | +| 3973 | 电信 | 甘肃兰州 | +| 5317 | 电信 | 江苏连云港5G | +| 5396 | 电信 | 江苏苏州5G | +| 7509 | 电信 | 浙江杭州 | +| 17145 | 电信 | 安徽合肥5G | +| 19076 | 电信 | 重庆 | +| 23844 | 电信 | 湖北武汉 | +| 24012 | 电信 | 内蒙古呼和浩特 | +| 26352 | 电信 | 江苏南京5G | +| 27377 | 电信 | 北京5G | +| 27575 | 电信 | 新疆乌鲁木齐 | +| 27594 | 电信 | 广东广州5G | +| 27810 | 电信 | 广西南宁 | +| 28225 | 电信 | 湖南长沙5G | +| 29026 | 电信 | 四川成都 | +| 29071 | 电信 | 四川成都 | +| 29353 | 电信 | 湖北武汉5G | + +联通: + +| 服务器ID | 运营商 | 位置 | +| ----- | ---- | -------------- | +| 2461 | 联通 | 四川成都 | +| 4690 | 联通 | 甘肃兰州 | +| 4863 | 联通 | 陕西西安 | +| 4870 | 联通 | 湖南长沙 | +| 4884 | 联通 | 福建福州 | +| 5039 | 联通 | 山东济南 | +| 5103 | 联通 | 云南昆明 | +| 5145 | 联通 | 北京 | +| 5485 | 联通 | 湖北武汉 | +| 5505 | 联通 | 北京 | +| 5509 | 联通 | 宁夏银川 | +| 5724 | 联通 | 安徽合肥 | +| 6144 | 联通 | 新疆乌鲁木齐 | +| 9484 | 联通 | 吉林长春 | +| 13704 | 联通 | 江苏南京 | +| 16192 | 联通 | 广东深圳 | +| 21005 | 联通 | 上海 | +| 24447 | 联通 | 上海5G | +| 26180 | 联通 | 山东济南5G | +| 26677 | 联通 | 湖南株洲 | +| 26678 | 联通 | 广东广州5G | +| 27154 | 联通 | 天津5G | +| 31985 | 联通 | 重庆 | + +移动: + +| 服务器ID | 运营商 | 位置 | +| ----- | ---- | ------------------ | +| 4515 | 移动 | 广东深圳 | +| 4647 | 移动 | 浙江杭州 | +| 6611 | 移动 | 广东广州 | +| 6715 | 移动 | 浙江宁波5G | +| 15863 | 移动 | 广西南宁 | +| 16145 | 移动 | 甘肃兰州 | +| 16167 | 移动 | 辽宁沈阳 | +| 16171 | 移动 | 福建福州 | +| 16375 | 移动 | 吉林长春 | +| 16398 | 移动 | 贵州贵阳 | +| 16503 | 移动 | 海南海口 | +| 16858 | 移动 | 新疆乌鲁木齐 | +| 17184 | 移动 | 天津5G | +| 17222 | 移动 | 新疆阿勒泰 | +| 17223 | 移动 | 河北石家庄 | +| 17227 | 移动 | 新疆和田 | +| 17245 | 移动 | 新疆喀什 | +| 17320 | 移动 | 江苏镇江5G | +| 17584 | 移动 | 重庆 | +| 18444 | 移动 | 西藏拉萨 | +| 21845 | 移动 | 江苏常州5G | +| 24337 | 移动 | 四川成都 | +| 25637 | 移动 | 上海5G | +| 25728 | 移动 | 辽宁大连 | +| 25858 | 移动 | 北京 | +| 25881 | 移动 | 山东济南5G | +| 25883 | 移动 | 江西南昌5G | +| 26331 | 移动 | 河南郑州5G | +| 26380 | 移动 | 陕西西安 | +| 26404 | 移动 | 安徽合肥5G | +| 26501 | 移动 | 山西太原5G | +| 26656 | 移动 | 黑龙江哈尔滨 | +| 26728 | 移动 | 云南昆明 | +| 26850 | 移动 | 江苏无锡5G | +| 26938 | 移动 | 新疆乌鲁木齐5G | +| 26940 | 移动 | 宁夏银川 | +| 27019 | 移动 | 内蒙古呼和浩特 | +| 27100 | 移动 | 山东青岛5G | +| 27151 | 移动 | 山东临沂5G | +| 27249 | 移动 | 江苏南京5G | +| 28491 | 移动 | 湖南长沙5G | +| 29083 | 移动 | 青海西宁5G | +| 29105 | 移动 | 陕西西安5G | +| 30154 | 移动 | 上海 | +| 30232 | 移动 | 内蒙古呼和浩特5G | +| 30293 | 移动 | 内蒙古通辽5G | +| 31520 | 移动 | 广东中山 | +| 31815 | 移动 | 宁夏银川 | \ No newline at end of file diff --git a/SuperSpeed.png b/SuperSpeed.png new file mode 100644 index 0000000..6dd550a Binary files /dev/null and b/SuperSpeed.png differ diff --git a/ip_info.py b/ip_info.py deleted file mode 100644 index eb06c6d..0000000 --- a/ip_info.py +++ /dev/null @@ -1,14 +0,0 @@ -#!/usr/bin/env python -# -*- coding: UTF-8 -*- - -import urllib2 -import json -import sys -reload(sys) -sys.setdefaultencoding('utf-8') - -ip_api = urllib2.urlopen(r'http://ip-api.com/json') - -ijson = json.loads(ip_api.read()) - -print ijson[sys.argv[1].encode('utf-8')] \ No newline at end of file diff --git a/ipip.py b/ipip.py deleted file mode 100644 index 323c1ef..0000000 --- a/ipip.py +++ /dev/null @@ -1,14 +0,0 @@ -#!/usr/bin/env python -# -*- coding: UTF-8 -*- - -import urllib2 -import json -import sys -reload(sys) -sys.setdefaultencoding('utf-8') - -f = open("ip_json.json",'r') -ijson = json.load(f) -jjson = ijson['location'] - -print jjson[sys.argv[1].encode('utf-8')] \ No newline at end of file diff --git a/superbench.sh b/superbench.sh deleted file mode 100644 index 4f14051..0000000 --- a/superbench.sh +++ /dev/null @@ -1,757 +0,0 @@ -#!/usr/bin/env bash -# -# Description: Auto system info & I/O test & network to China script -# -# Copyright (C) 2017 - 2018 Oldking -# -# Thanks: Bench.sh -# -# URL: https://www.oldking.net/350.html -# - -# Colors -RED='\033[0;31m' -GREEN='\033[0;32m' -YELLOW='\033[0;33m' -SKYBLUE='\033[0;36m' -PLAIN='\033[0m' - -about() { - echo "" - echo " ========================================================= " - echo " \ Superbench.sh Script / " - echo " \ Basic system info, I/O test and speedtest / " - echo " \ v1.1.4 (1 Jan 2019) / " - echo " \ Created by Oldking / " - echo " ========================================================= " - echo "" - echo " Intro: https://www.oldking.net/350.html" - echo " Copyright (C) 2019 Oldking oooldking@gmail.com" - echo -e " ${RED}Happy New Year!${PLAIN}" - echo "" -} - -cancel() { - echo "" - next; - echo " Abort ..." - echo " Cleanup ..." - cleanup; - echo " Done" - exit -} - -trap cancel SIGINT - -benchinit() { - # check release - if [ -f /etc/redhat-release ]; then - release="centos" - elif cat /etc/issue | grep -Eqi "debian"; then - release="debian" - elif cat /etc/issue | grep -Eqi "ubuntu"; then - release="ubuntu" - elif cat /etc/issue | grep -Eqi "centos|red hat|redhat"; then - release="centos" - elif cat /proc/version | grep -Eqi "debian"; then - release="debian" - elif cat /proc/version | grep -Eqi "ubuntu"; then - release="ubuntu" - elif cat /proc/version | grep -Eqi "centos|red hat|redhat"; then - release="centos" - fi - - # check root - [[ $EUID -ne 0 ]] && echo -e "${RED}Error:${PLAIN} This script must be run as root!" && exit 1 - - # check python - if [ ! -e '/usr/bin/python' ]; then - #echo -e - #read -p "${RED}Error:${PLAIN} python is not install. You must be install python command at first.\nDo you want to install? [y/n]" is_install - #if [[ ${is_install} == "y" || ${is_install} == "Y" ]]; then - echo " Installing Python ..." - if [ "${release}" == "centos" ]; 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 - #else - # exit - #fi - - fi - - # check curl - if [ ! -e '/usr/bin/curl' ]; then - #echo -e - #read -p "${RED}Error:${PLAIN} curl is not install. You must be install curl command at first.\nDo you want to install? [y/n]" is_install - #if [[ ${is_install} == "y" || ${is_install} == "Y" ]]; then - echo " Installing Curl ..." - if [ "${release}" == "centos" ]; 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 - #else - # exit - #fi - fi - - # check wget - if [ ! -e '/usr/bin/wget' ]; then - #echo -e - #read -p "${RED}Error:${PLAIN} wget is not install. You must be install wget command at first.\nDo you want to install? [y/n]" is_install - #if [[ ${is_install} == "y" || ${is_install} == "Y" ]]; then - echo " Installing Wget ..." - if [ "${release}" == "centos" ]; 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 - #else - # exit - #fi - fi - - # install virt-what - #if [ ! -e '/usr/sbin/virt-what' ]; then - # echo "Installing Virt-what ..." - # if [ "${release}" == "centos" ]; then - # yum update > /dev/null 2>&1 - # yum -y install virt-what > /dev/null 2>&1 - # else - # apt-get update > /dev/null 2>&1 - # apt-get -y install virt-what > /dev/null 2>&1 - # fi - #fi - - # install jq - #if [ ! -e '/usr/bin/jq' ]; then - # echo " Installing Jq ..." - # if [ "${release}" == "centos" ]; then - # yum update > /dev/null 2>&1 - # yum -y install jq > /dev/null 2>&1 - # else - # apt-get update > /dev/null 2>&1 - # apt-get -y install jq > /dev/null 2>&1 - # fi - #fi - - # install speedtest-cli - if [ ! -e 'speedtest.py' ]; then - echo " Installing Speedtest-cli ..." - wget --no-check-certificate https://raw.github.com/sivel/speedtest-cli/master/speedtest.py > /dev/null 2>&1 - fi - chmod a+rx speedtest.py - - - # install tools.py - if [ ! -e 'tools.py' ]; then - echo " Installing tools.py ..." - wget --no-check-certificate https://raw.githubusercontent.com/oooldking/script/master/tools.py > /dev/null 2>&1 - fi - chmod a+rx tools.py - - # install fast.com-cli - if [ ! -e 'fast_com.py' ]; then - echo " Installing Fast.com-cli ..." - wget --no-check-certificate https://raw.githubusercontent.com/sanderjo/fast.com/master/fast_com.py > /dev/null 2>&1 - wget --no-check-certificate https://raw.githubusercontent.com/sanderjo/fast.com/master/fast_com_example_usage.py > /dev/null 2>&1 - fi - chmod a+rx fast_com.py - chmod a+rx fast_com_example_usage.py - - sleep 5 - - # start - start=$(date +%s) -} - -get_opsy() { - [ -f /etc/redhat-release ] && awk '{print ($1,$3~/^[0-9]/?$3:$4)}' /etc/redhat-release && return - [ -f /etc/os-release ] && awk -F'[= "]' '/PRETTY_NAME/{print $3,$4,$5}' /etc/os-release && return - [ -f /etc/lsb-release ] && awk -F'[="]+' '/DESCRIPTION/{print $2}' /etc/lsb-release && return -} - -next() { - printf "%-70s\n" "-" | sed 's/\s/-/g' | tee -a $log -} - -speed_test(){ - if [[ $1 == '' ]]; then - temp=$(python speedtest.py --share 2>&1) - is_down=$(echo "$temp" | grep 'Download') - result_speed=$(echo "$temp" | awk -F ' ' '/results/{print $3}') - if [[ ${is_down} ]]; then - local REDownload=$(echo "$temp" | awk -F ':' '/Download/{print $2}') - local reupload=$(echo "$temp" | awk -F ':' '/Upload/{print $2}') - local relatency=$(echo "$temp" | awk -F ':' '/Hosted/{print $2}') - - temp=$(echo "$relatency" | awk -F '.' '{print $1}') - if [[ ${temp} -gt 50 ]]; then - relatency=" (*)"${relatency} - fi - local nodeName=$2 - - 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 "${YELLOW}%-17s${GREEN}%-18s${RED}%-20s${SKYBLUE}%-12s${PLAIN}\n" " ${nodeName}" "${reupload}" "${REDownload}" "${relatency}" | tee -a $log - fi - else - local cerror="ERROR" - fi - else - temp=$(python speedtest.py --server $1 --share 2>&1) - is_down=$(echo "$temp" | grep 'Download') - if [[ ${is_down} ]]; then - local REDownload=$(echo "$temp" | awk -F ':' '/Download/{print $2}') - local reupload=$(echo "$temp" | awk -F ':' '/Upload/{print $2}') - local relatency=$(echo "$temp" | awk -F ':' '/Hosted/{print $2}') - #local relatency=$(pingtest $3) - #temp=$(echo "$relatency" | awk -F '.' '{print $1}') - #if [[ ${temp} -gt 1000 ]]; then - relatency=" - " - #fi - local nodeName=$2 - - 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 "${YELLOW}%-17s${GREEN}%-18s${RED}%-20s${SKYBLUE}%-12s${PLAIN}\n" " ${nodeName}" "${reupload}" "${REDownload}" "${relatency}" | tee -a $log - fi - else - local cerror="ERROR" - fi - fi -} - -print_speedtest() { - printf "%-18s%-18s%-20s%-12s\n" " Node Name" "Upload Speed" "Download Speed" "Latency" | tee -a $log - speed_test '' 'Speedtest.net' - speed_fast_com - speed_test '5316' 'Nanjing CT' - speed_test '12637' 'Xiangyang CT' - speed_test '7509' 'Hangzhou CT' - speed_test '19076' 'Chongqing CT' - speed_test '5083' 'Shanghai CU' - speed_test '4863' "Xi'an CU" - speed_test '5726' 'Chongqing CU' - speed_test '4665' 'Shanghai CM' - speed_test '4575' 'Chengdu CM' - speed_test '6168' 'Kunming CM' - speed_test '6611' 'Guangzhou CM' - - rm -rf speedtest.py -} - -print_speedtest_fast() { - printf "%-18s%-18s%-20s%-12s\n" " Node Name" "Upload Speed" "Download Speed" "Latency" | tee -a $log - speed_test '' 'Speedtest.net' - speed_fast_com - speed_test '7509' 'Hangzhou CT' - speed_test '5083' 'Shanghai CU' - speed_test '4575' 'Chengdu CM' - - rm -rf speedtest.py -} - -speed_fast_com() { - temp=$(python fast_com_example_usage.py 2>&1) - is_down=$(echo "$temp" | grep 'Result') - if [[ ${is_down} ]]; then - temp1=$(echo "$temp" | awk -F ':' '/Result/{print $2}') - temp2=$(echo "$temp1" | awk -F ' ' '/Mbps/{print $1}') - local REDownload="$temp2 Mbit/s" - local reupload="0.00 Mbit/s" - local relatency="-" - local nodeName="Fast.com" - - printf "${YELLOW}%-18s${GREEN}%-18s${RED}%-20s${SKYBLUE}%-12s${PLAIN}\n" " ${nodeName}" "${reupload}" "${REDownload}" "${relatency}" | tee -a $log - else - local cerror="ERROR" - fi - rm -rf fast_com_example_usage.py - rm -rf fast_com.py - -} - -io_test() { - (LANG=C dd if=/dev/zero of=test_file_$$ bs=512K count=$1 conv=fdatasync && rm -f test_file_$$ ) 2>&1 | awk -F, '{io=$NF} END { print io}' | sed 's/^[ \t]*//;s/[ \t]*$//' -} - -calc_disk() { - local total_size=0 - local array=$@ - for size in ${array[@]} - do - [ "${size}" == "0" ] && size_t=0 || size_t=`echo ${size:0:${#size}-1}` - [ "`echo ${size:(-1)}`" == "K" ] && size=0 - [ "`echo ${size:(-1)}`" == "M" ] && size=$( awk 'BEGIN{printf "%.1f", '$size_t' / 1024}' ) - [ "`echo ${size:(-1)}`" == "T" ] && size=$( awk 'BEGIN{printf "%.1f", '$size_t' * 1024}' ) - [ "`echo ${size:(-1)}`" == "G" ] && size=${size_t} - total_size=$( awk 'BEGIN{printf "%.1f", '$total_size' + '$size'}' ) - done - echo ${total_size} -} - -power_time() { - - result=$(smartctl -a $(result=$(cat /proc/mounts) && echo $(echo "$result" | awk '/data=ordered/{print $1}') | awk '{print $1}') 2>&1) && power_time=$(echo "$result" | awk '/Power_On/{print $10}') && echo "$power_time" -} - -install_smart() { - # install smartctl - if [ ! -e '/usr/sbin/smartctl' ]; then - echo "Installing Smartctl ..." - if [ "${release}" == "centos" ]; then - yum update > /dev/null 2>&1 - yum -y install smartmontools > /dev/null 2>&1 - else - apt-get update > /dev/null 2>&1 - apt-get -y install smartmontools > /dev/null 2>&1 - fi - fi -} - -ip_info(){ - # use jq tool - result=$(curl -s 'http://ip-api.com/json') - country=$(echo $result | jq '.country' | sed 's/\"//g') - city=$(echo $result | jq '.city' | sed 's/\"//g') - isp=$(echo $result | jq '.isp' | sed 's/\"//g') - as_tmp=$(echo $result | jq '.as' | sed 's/\"//g') - asn=$(echo $as_tmp | awk -F ' ' '{print $1}') - org=$(echo $result | jq '.org' | sed 's/\"//g') - countryCode=$(echo $result | jq '.countryCode' | sed 's/\"//g') - region=$(echo $result | jq '.regionName' | sed 's/\"//g') - if [ -z "$city" ]; then - city=${region} - fi - - echo -e " ASN & ISP : ${SKYBLUE}$asn, $isp${PLAIN}" | tee -a $log - echo -e " Organization : ${YELLOW}$org${PLAIN}" | tee -a $log - echo -e " Location : ${SKYBLUE}$city, ${YELLOW}$country / $countryCode${PLAIN}" | tee -a $log - echo -e " Region : ${SKYBLUE}$region${PLAIN}" | tee -a $log -} - -ip_info2(){ - # no jq - country=$(curl -s https://ipapi.co/country_name/) - city=$(curl -s https://ipapi.co/city/) - asn=$(curl -s https://ipapi.co/asn/) - org=$(curl -s https://ipapi.co/org/) - countryCode=$(curl -s https://ipapi.co/country/) - region=$(curl -s https://ipapi.co/region/) - - echo -e " ASN & ISP : ${SKYBLUE}$asn${PLAIN}" | tee -a $log - echo -e " Organization : ${SKYBLUE}$org${PLAIN}" | tee -a $log - echo -e " Location : ${SKYBLUE}$city, ${GREEN}$country / $countryCode${PLAIN}" | tee -a $log - echo -e " Region : ${SKYBLUE}$region${PLAIN}" | tee -a $log -} - -ip_info3(){ - # use python tool - country=$(python ip_info.py country) - city=$(python ip_info.py city) - isp=$(python ip_info.py isp) - as_tmp=$(python ip_info.py as) - asn=$(echo $as_tmp | awk -F ' ' '{print $1}') - org=$(python ip_info.py org) - countryCode=$(python ip_info.py countryCode) - region=$(python ip_info.py regionName) - - echo -e " ASN & ISP : ${SKYBLUE}$asn, $isp${PLAIN}" | tee -a $log - echo -e " Organization : ${GREEN}$org${PLAIN}" | tee -a $log - echo -e " Location : ${SKYBLUE}$city, ${GREEN}$country / $countryCode${PLAIN}" | tee -a $log - echo -e " Region : ${SKYBLUE}$region${PLAIN}" | tee -a $log - - rm -rf ip_info.py -} - -ip_info4(){ - ip_date=$(curl -4 -s http://api.ip.la/en?json) - echo $ip_date > ip_json.json - isp=$(python tools.py geoip isp) - as_tmp=$(python tools.py geoip as) - asn=$(echo $as_tmp | awk -F ' ' '{print $1}') - org=$(python tools.py geoip org) - if [ -z "ip_date" ]; then - echo $ip_date - echo "hala" - country=$(python tools.py ipip country_name) - city=$(python tools.py ipip city) - countryCode=$(python tools.py ipip country_code) - region=$(python tools.py ipip province) - else - country=$(python tools.py geoip country) - city=$(python tools.py geoip city) - countryCode=$(python tools.py geoip countryCode) - region=$(python tools.py geoip regionName) - fi - if [ -z "$city" ]; then - city=${region} - fi - - echo -e " ASN & ISP : ${SKYBLUE}$asn, $isp${PLAIN}" | tee -a $log - echo -e " Organization : ${YELLOW}$org${PLAIN}" | tee -a $log - echo -e " Location : ${SKYBLUE}$city, ${YELLOW}$country / $countryCode${PLAIN}" | tee -a $log - echo -e " Region : ${SKYBLUE}$region${PLAIN}" | tee -a $log - - rm -rf tools.py - rm -rf ip_json.json -} - -virt_check(){ - if hash ifconfig 2>/dev/null; then - eth=$(ifconfig) - fi - - virtualx=$(dmesg) 2>/dev/null - - # check dmidecode cmd - if [ $(which dmidecode) ]; then - sys_manu=$(dmidecode -s system-manufacturer) 2>/dev/null - sys_product=$(dmidecode -s system-product-name) 2>/dev/null - sys_ver=$(dmidecode -s system-version) 2>/dev/null - else - sys_manu="" - sys_product="" - sys_ver="" - fi - - if grep docker /proc/1/cgroup -qa; then - virtual="Docker" - elif grep lxc /proc/1/cgroup -qa; then - virtual="Lxc" - elif grep -qa container=lxc /proc/1/environ; then - virtual="Lxc" - elif [[ -f /proc/user_beancounters ]]; then - virtual="OpenVZ" - elif [[ "$virtualx" == *kvm-clock* ]]; then - virtual="KVM" - elif [[ "$cname" == *KVM* ]]; then - virtual="KVM" - elif [[ "$virtualx" == *"VMware Virtual Platform"* ]]; then - virtual="VMware" - elif [[ "$virtualx" == *"Parallels Software International"* ]]; then - virtual="Parallels" - elif [[ "$virtualx" == *VirtualBox* ]]; then - virtual="VirtualBox" - elif [[ -e /proc/xen ]]; then - virtual="Xen" - elif [[ "$sys_manu" == *"Microsoft Corporation"* ]]; then - if [[ "$sys_product" == *"Virtual Machine"* ]]; then - if [[ "$sys_ver" == *"7.0"* || "$sys_ver" == *"Hyper-V" ]]; then - virtual="Hyper-V" - else - virtual="Microsoft Virtual Machine" - fi - fi - else - virtual="Dedicated" - fi -} - -power_time_check(){ - echo -ne " Power time of disk : " - install_smart - ptime=$(power_time) - echo -e "${SKYBLUE}$ptime Hours${PLAIN}" -} - -freedisk() { - # check free space - #spacename=$( df -m . | awk 'NR==2 {print $1}' ) - #spacenamelength=$(echo ${spacename} | awk '{print length($0)}') - #if [[ $spacenamelength -gt 20 ]]; then - # freespace=$( df -m . | awk 'NR==3 {print $3}' ) - #else - # freespace=$( df -m . | awk 'NR==2 {print $4}' ) - #fi - freespace=$( df -m . | awk 'NR==2 {print $4}' ) - if [[ $freespace == "" ]]; then - $freespace=$( df -m . | awk 'NR==3 {print $3}' ) - fi - if [[ $freespace -gt 1024 ]]; then - printf "%s" $((1024*2)) - elif [[ $freespace -gt 512 ]]; then - printf "%s" $((512*2)) - elif [[ $freespace -gt 256 ]]; then - printf "%s" $((256*2)) - elif [[ $freespace -gt 128 ]]; then - printf "%s" $((128*2)) - else - printf "1" - fi -} - -print_io() { - if [[ $1 == "fast" ]]; then - writemb=$((128*2)) - else - writemb=$(freedisk) - fi - - writemb_size="$(( writemb / 2 ))MB" - if [[ $writemb_size == "1024MB" ]]; then - writemb_size="1.0GB" - fi - - if [[ $writemb != "1" ]]; then - echo -n " I/O Speed( $writemb_size ) : " | tee -a $log - io1=$( io_test $writemb ) - echo -e "${YELLOW}$io1${PLAIN}" | tee -a $log - echo -n " I/O Speed( $writemb_size ) : " | tee -a $log - io2=$( io_test $writemb ) - echo -e "${YELLOW}$io2${PLAIN}" | tee -a $log - echo -n " I/O Speed( $writemb_size ) : " | tee -a $log - io3=$( io_test $writemb ) - echo -e "${YELLOW}$io3${PLAIN}" | tee -a $log - ioraw1=$( echo $io1 | awk 'NR==1 {print $1}' ) - [ "`echo $io1 | awk 'NR==1 {print $2}'`" == "GB/s" ] && ioraw1=$( awk 'BEGIN{print '$ioraw1' * 1024}' ) - ioraw2=$( echo $io2 | awk 'NR==1 {print $1}' ) - [ "`echo $io2 | awk 'NR==1 {print $2}'`" == "GB/s" ] && ioraw2=$( awk 'BEGIN{print '$ioraw2' * 1024}' ) - ioraw3=$( echo $io3 | awk 'NR==1 {print $1}' ) - [ "`echo $io3 | awk 'NR==1 {print $2}'`" == "GB/s" ] && ioraw3=$( awk 'BEGIN{print '$ioraw3' * 1024}' ) - ioall=$( awk 'BEGIN{print '$ioraw1' + '$ioraw2' + '$ioraw3'}' ) - ioavg=$( awk 'BEGIN{printf "%.1f", '$ioall' / 3}' ) - echo -e " Average I/O Speed : ${YELLOW}$ioavg MB/s${PLAIN}" | tee -a $log - else - echo -e " ${RED}Not enough space!${PLAIN}" - fi -} - -print_system_info() { - echo -e " CPU Model : ${SKYBLUE}$cname${PLAIN}" | tee -a $log - echo -e " CPU Cores : ${YELLOW}$cores Cores ${SKYBLUE}@ $freq MHz $arch${PLAIN}" | tee -a $log - echo -e " CPU Cache : ${SKYBLUE}$corescache ${PLAIN}" | tee -a $log - echo -e " OS : ${SKYBLUE}$opsy ($lbit Bit) ${YELLOW}$virtual${PLAIN}" | tee -a $log - echo -e " Kernel : ${SKYBLUE}$kern${PLAIN}" | tee -a $log - echo -e " Total Space : ${SKYBLUE}$disk_used_size GB / ${YELLOW}$disk_total_size GB ${PLAIN}" | tee -a $log - echo -e " Total RAM : ${SKYBLUE}$uram MB / ${YELLOW}$tram MB ${SKYBLUE}($bram MB Buff)${PLAIN}" | tee -a $log - echo -e " Total SWAP : ${SKYBLUE}$uswap MB / $swap MB${PLAIN}" | tee -a $log - echo -e " Uptime : ${SKYBLUE}$up${PLAIN}" | tee -a $log - echo -e " Load Average : ${SKYBLUE}$load${PLAIN}" | tee -a $log - echo -e " TCP CC : ${YELLOW}$tcpctrl${PLAIN}" | tee -a $log -} - -print_end_time() { - end=$(date +%s) - time=$(( $end - $start )) - if [[ $time -gt 60 ]]; then - min=$(expr $time / 60) - sec=$(expr $time % 60) - echo -ne " Finished in : ${min} min ${sec} sec" | tee -a $log - else - echo -ne " Finished in : ${time} sec" | tee -a $log - fi - #echo -ne "\n Current time : " - #echo $(date +%Y-%m-%d" "%H:%M:%S) - printf '\n' | tee -a $log - #utc_time=$(date -u '+%F %T') - #bj_time=$(date +%Y-%m-%d" "%H:%M:%S -d '+8 hours') - bj_time=$(curl -s http://cgi.im.qq.com/cgi-bin/cgi_svrtime) - #utc_time=$(date +"$bj_time" -d '-8 hours') - - if [[ $(echo $bj_time | grep "html") ]]; then - bj_time=$(date -u +%Y-%m-%d" "%H:%M:%S -d '+8 hours') - fi - echo " Timestamp : $bj_time GMT+8" | tee -a $log - #echo " Finished!" - echo " Results : $log" -} - -get_system_info() { - cname=$( awk -F: '/model name/ {name=$2} END {print name}' /proc/cpuinfo | sed 's/^[ \t]*//;s/[ \t]*$//' ) - cores=$( awk -F: '/model name/ {core++} END {print core}' /proc/cpuinfo ) - freq=$( awk -F: '/cpu MHz/ {freq=$2} END {print freq}' /proc/cpuinfo | sed 's/^[ \t]*//;s/[ \t]*$//' ) - corescache=$( awk -F: '/cache size/ {cache=$2} END {print cache}' /proc/cpuinfo | sed 's/^[ \t]*//;s/[ \t]*$//' ) - tram=$( free -m | awk '/Mem/ {print $2}' ) - uram=$( free -m | awk '/Mem/ {print $3}' ) - bram=$( free -m | awk '/Mem/ {print $6}' ) - swap=$( free -m | awk '/Swap/ {print $2}' ) - uswap=$( free -m | awk '/Swap/ {print $3}' ) - up=$( awk '{a=$1/86400;b=($1%86400)/3600;c=($1%3600)/60} {printf("%d days %d hour %d min\n",a,b,c)}' /proc/uptime ) - load=$( w | head -1 | awk -F'load average:' '{print $2}' | sed 's/^[ \t]*//;s/[ \t]*$//' ) - opsy=$( get_opsy ) - arch=$( uname -m ) - lbit=$( getconf LONG_BIT ) - kern=$( uname -r ) - #ipv6=$( wget -qO- -t1 -T2 ipv6.icanhazip.com ) - disk_size1=($( LANG=C df -hPl | grep -wvE '\-|none|tmpfs|overlay|shm|udev|devtmpfs|by-uuid|chroot|Filesystem' | awk '{print $2}' )) - disk_size2=($( LANG=C df -hPl | grep -wvE '\-|none|tmpfs|overlay|shm|udev|devtmpfs|by-uuid|chroot|Filesystem' | awk '{print $3}' )) - disk_total_size=$( calc_disk ${disk_size1[@]} ) - disk_used_size=$( calc_disk ${disk_size2[@]} ) - #tcp congestion control - tcpctrl=$( sysctl net.ipv4.tcp_congestion_control | awk -F ' ' '{print $3}' ) - - #tmp=$(python tools.py disk 0) - #disk_total_size=$(echo $tmp | sed s/G//) - #tmp=$(python tools.py disk 1) - #disk_used_size=$(echo $tmp | sed s/G//) - - virt_check -} - -print_intro() { - printf ' Superbench.sh -- https://www.oldking.net/350.html\n' | tee -a $log - printf " Mode : \e${GREEN}%s\e${PLAIN} Version : \e${GREEN}%s${PLAIN}\n" $mode_name 1.1.4 | tee -a $log - printf ' Usage : wget -qO- git.io/superbench.sh | bash\n' | tee -a $log -} - -sharetest() { - echo " Share result:" | tee -a $log - echo " · $result_speed" | tee -a $log - log_preupload - case $1 in - 'ubuntu') - share_link=$( curl -v --data-urlencode "content@$log_up" -d "poster=superbench.sh" -d "syntax=text" "https://paste.ubuntu.com" 2>&1 | \ - grep "Location" | awk '{print $3}' );; - 'haste' ) - share_link=$( curl -X POST -s -d "$(cat $log)" https://hastebin.com/documents | awk -F '"' '{print "https://hastebin.com/"$4}' );; - 'clbin' ) - share_link=$( curl -sF 'clbin=<-' https://clbin.com < $log );; - 'ptpb' ) - share_link=$( curl -sF c=@- https://ptpb.pw/?u=1 < $log );; - esac - - # print result info - echo " · $share_link" | tee -a $log - next - echo "" - rm -f $log_up - -} - -log_preupload() { - log_up="$HOME/superbench_upload.log" - true > $log_up - $(cat superbench.log 2>&1 | sed -r "s/\x1B\[([0-9]{1,2}(;[0-9]{1,2})?)?[m|K]//g" > $log_up) -} - -get_ip_whois_org_name(){ - #ip=$(curl -s ip.sb) - result=$(curl -s https://rest.db.ripe.net/search.json?query-string=$(curl -s ip.sb)) - #org_name=$(echo $result | jq '.objects.object.[1].attributes.attribute.[1].value' | sed 's/\"//g') - org_name=$(echo $result | jq '.objects.object[1].attributes.attribute[1]' | sed 's/\"//g') - echo $org_name; -} - -pingtest() { - local ping_ms=$( ping -w 1 -c 1 $1 | grep 'rtt' | cut -d"/" -f5 ) - - # get download speed and print - if [[ $ping_ms == "" ]]; then - printf "ping error!" | tee -a $log - else - printf "%3i.%s ms" "${ping_ms%.*}" "${ping_ms#*.}" | tee -a $log - fi -} - -cleanup() { - rm -f test_file_*; - rm -f speedtest.py; - rm -f fast_com*; - rm -f tools.py; - rm -f ip_json.json -} - -bench_all(){ - mode_name="Standard" - about; - benchinit; - clear - next; - print_intro; - next; - get_system_info; - print_system_info; - ip_info4; - next; - print_io; - next; - print_speedtest; - next; - print_end_time; - next; - cleanup; - sharetest ubuntu; -} - -fast_bench(){ - mode_name="Fast" - about; - benchinit; - clear - next; - print_intro; - next; - get_system_info; - print_system_info; - ip_info4; - next; - print_io fast; - next; - print_speedtest_fast; - next; - print_end_time; - next; - cleanup; -} - - - - -log="$HOME/superbench.log" -true > $log - -case $1 in - 'info'|'-i'|'--i'|'-info'|'--info' ) - about;sleep 3;next;get_system_info;print_system_info;next;; - 'version'|'-v'|'--v'|'-version'|'--version') - next;about;next;; - 'io'|'-io'|'--io'|'-drivespeed'|'--drivespeed' ) - next;print_io;next;; - 'speed'|'-speed'|'--speed'|'-speedtest'|'--speedtest'|'-speedcheck'|'--speedcheck' ) - about;benchinit;next;print_speedtest;next;cleanup;; - 'ip'|'-ip'|'--ip'|'geoip'|'-geoip'|'--geoip' ) - about;benchinit;next;ip_info4;next;cleanup;; - 'bench'|'-a'|'--a'|'-all'|'--all'|'-bench'|'--bench' ) - bench_all;; - 'about'|'-about'|'--about' ) - about;; - 'fast'|'-f'|'--f'|'-fast'|'--fast' ) - fast_bench;; - 'share'|'-s'|'--s'|'-share'|'--share' ) - bench_all; - is_share="share" - if [[ $2 == "" ]]; then - sharetest ubuntu; - else - sharetest $2; - fi - ;; - 'debug'|'-d'|'--d'|'-debug'|'--debug' ) - get_ip_whois_org_name;; -*) - bench_all;; -esac - - - -if [[ ! $is_share == "share" ]]; then - case $2 in - 'share'|'-s'|'--s'|'-share'|'--share' ) - if [[ $3 == '' ]]; then - sharetest ubuntu; - else - sharetest $3; - fi - ;; - esac -fi diff --git a/superbench_git.sh b/superbench_git.sh deleted file mode 100644 index d5868c6..0000000 --- a/superbench_git.sh +++ /dev/null @@ -1,601 +0,0 @@ -#!/usr/bin/env bash -# -# Description: Auto system info & I/O test & network to China script -# -# Copyright (C) 2017 - 2018 Oldking -# -# Thanks: Bench.sh -# -# URL: https://www.oldking.net/350.html -# - -RED='\033[0;31m' -GREEN='\033[0;32m' -YELLOW='\033[0;33m' -SKYBLUE='\033[0;36m' -PLAIN='\033[0m' - -about() { - echo "" - echo " ========================================================= " - echo " \ Superbench.sh Script / " - echo " \ Basic system info, I/O test and speedtest / " - echo " \ v1.1.4 (1 Jan 2019) / " - echo " \ Created by Oldking / " - echo " ========================================================= " - echo "" - echo " Intro: https://www.oldking.net/350.html" - echo " Copyright (C) 2019 Oldking oooldking@gmail.com" - echo -e " ${RED}Happy New Year!${PLAIN}" - echo "" -} - -cancel() { - echo "" - next; - echo " Abort ..." - echo " Cleanup ..." - cleanup; - echo " Done" - exit -} - -trap cancel SIGINT - -benchinit() { - if [ -f /etc/redhat-release ]; then - release="centos" - elif cat /etc/issue | grep -Eqi "debian"; then - release="debian" - elif cat /etc/issue | grep -Eqi "ubuntu"; then - release="ubuntu" - elif cat /etc/issue | grep -Eqi "centos|red hat|redhat"; then - release="centos" - elif cat /proc/version | grep -Eqi "debian"; then - release="debian" - elif cat /proc/version | grep -Eqi "ubuntu"; then - release="ubuntu" - elif cat /proc/version | grep -Eqi "centos|red hat|redhat"; then - release="centos" - fi - - [[ $EUID -ne 0 ]] && echo -e "${RED}Error:${PLAIN} This script must be run as root!" && exit 1 - - if [ ! -e '/usr/bin/python' ]; then - echo " Installing Python ..." - if [ "${release}" == "centos" ]; 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 - - fi - - if [ ! -e '/usr/bin/curl' ]; then - echo " Installing Curl ..." - if [ "${release}" == "centos" ]; 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 - fi - - if [ ! -e '/usr/bin/wget' ]; then - echo " Installing Wget ..." - if [ "${release}" == "centos" ]; 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 - fi - - if [ ! -e 'speedtest.py' ]; then - echo " Installing Speedtest-cli ..." - wget --no-check-certificate https://raw.github.com/sivel/speedtest-cli/master/speedtest.py > /dev/null 2>&1 - fi - chmod a+rx speedtest.py - - if [ ! -e 'tools.py' ]; then - echo " Installing tools.py ..." - wget --no-check-certificate https://raw.githubusercontent.com/oooldking/script/master/tools.py > /dev/null 2>&1 - fi - chmod a+rx tools.py - - if [ ! -e 'fast_com.py' ]; then - echo " Installing Fast.com-cli ..." - wget --no-check-certificate https://raw.githubusercontent.com/sanderjo/fast.com/master/fast_com.py > /dev/null 2>&1 - wget --no-check-certificate https://raw.githubusercontent.com/sanderjo/fast.com/master/fast_com_example_usage.py > /dev/null 2>&1 - fi - chmod a+rx fast_com.py - chmod a+rx fast_com_example_usage.py - - sleep 5 - - start=$(date +%s) -} - -get_opsy() { - [ -f /etc/redhat-release ] && awk '{print ($1,$3~/^[0-9]/?$3:$4)}' /etc/redhat-release && return - [ -f /etc/os-release ] && awk -F'[= "]' '/PRETTY_NAME/{print $3,$4,$5}' /etc/os-release && return - [ -f /etc/lsb-release ] && awk -F'[="]+' '/DESCRIPTION/{print $2}' /etc/lsb-release && return -} - -next() { - printf "%-70s\n" "-" | sed 's/\s/-/g' | tee -a $log -} - -speed_test(){ - if [[ $1 == '' ]]; then - temp=$(python speedtest.py --share 2>&1) - is_down=$(echo "$temp" | grep 'Download') - result_speed=$(echo "$temp" | awk -F ' ' '/results/{print $3}') - if [[ ${is_down} ]]; then - local REDownload=$(echo "$temp" | awk -F ':' '/Download/{print $2}') - local reupload=$(echo "$temp" | awk -F ':' '/Upload/{print $2}') - local relatency=$(echo "$temp" | awk -F ':' '/Hosted/{print $2}') - - temp=$(echo "$relatency" | awk -F '.' '{print $1}') - if [[ ${temp} -gt 50 ]]; then - relatency=" (*)"${relatency} - fi - local nodeName=$2 - - 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 "${YELLOW}%-17s${GREEN}%-18s${RED}%-20s${SKYBLUE}%-12s${PLAIN}\n" " ${nodeName}" "${reupload}" "${REDownload}" "${relatency}" | tee -a $log - fi - else - local cerror="ERROR" - fi - else - temp=$(python speedtest.py --server $1 --share 2>&1) - is_down=$(echo "$temp" | grep 'Download') - if [[ ${is_down} ]]; then - local REDownload=$(echo "$temp" | awk -F ':' '/Download/{print $2}') - local reupload=$(echo "$temp" | awk -F ':' '/Upload/{print $2}') - local relatency=$(echo "$temp" | awk -F ':' '/Hosted/{print $2}') - relatency=" - " - local nodeName=$2 - - 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 "${YELLOW}%-17s${GREEN}%-18s${RED}%-20s${SKYBLUE}%-12s${PLAIN}\n" " ${nodeName}" "${reupload}" "${REDownload}" "${relatency}" | tee -a $log - fi - else - local cerror="ERROR" - fi - fi -} - -print_speedtest() { - printf "%-18s%-18s%-20s%-12s\n" " Node Name" "Upload Speed" "Download Speed" "Latency" | tee -a $log - speed_test '' 'Speedtest.net' - speed_fast_com - speed_test '5316' 'Nanjing CT' - speed_test '12637' 'Xiangyang CT' - speed_test '7509' 'Hangzhou CT' - speed_test '19076' 'Chongqing CT' - speed_test '5083' 'Shanghai CU' - speed_test '4863' "Xi'an CU" - speed_test '5726' 'Chongqing CU' - speed_test '4665' 'Shanghai CM' - speed_test '4575' 'Chengdu CM' - speed_test '6168' 'Kunming CM' - speed_test '6611' 'Guangzhou CM' - - rm -rf speedtest.py -} - -print_speedtest_fast() { - printf "%-18s%-18s%-20s%-12s\n" " Node Name" "Upload Speed" "Download Speed" "Latency" | tee -a $log - speed_test '' 'Speedtest.net' - speed_fast_com - speed_test '7509' 'Hangzhou CT' - speed_test '5083' 'Shanghai CU' - speed_test '4575' 'Chengdu CM' - - rm -rf speedtest.py -} - -speed_fast_com() { - temp=$(python fast_com_example_usage.py 2>&1) - is_down=$(echo "$temp" | grep 'Result') - if [[ ${is_down} ]]; then - temp1=$(echo "$temp" | awk -F ':' '/Result/{print $2}') - temp2=$(echo "$temp1" | awk -F ' ' '/Mbps/{print $1}') - local REDownload="$temp2 Mbit/s" - local reupload="0.00 Mbit/s" - local relatency="-" - local nodeName="Fast.com" - - printf "${YELLOW}%-18s${GREEN}%-18s${RED}%-20s${SKYBLUE}%-12s${PLAIN}\n" " ${nodeName}" "${reupload}" "${REDownload}" "${relatency}" | tee -a $log - else - local cerror="ERROR" - fi - rm -rf fast_com_example_usage.py - rm -rf fast_com.py - -} - -io_test() { - (LANG=C dd if=/dev/zero of=test_file_$$ bs=512K count=$1 conv=fdatasync && rm -f test_file_$$ ) 2>&1 | awk -F, '{io=$NF} END { print io}' | sed 's/^[ \t]*//;s/[ \t]*$//' -} - -calc_disk() { - local total_size=0 - local array=$@ - for size in ${array[@]} - do - [ "${size}" == "0" ] && size_t=0 || size_t=`echo ${size:0:${#size}-1}` - [ "`echo ${size:(-1)}`" == "K" ] && size=0 - [ "`echo ${size:(-1)}`" == "M" ] && size=$( awk 'BEGIN{printf "%.1f", '$size_t' / 1024}' ) - [ "`echo ${size:(-1)}`" == "T" ] && size=$( awk 'BEGIN{printf "%.1f", '$size_t' * 1024}' ) - [ "`echo ${size:(-1)}`" == "G" ] && size=${size_t} - total_size=$( awk 'BEGIN{printf "%.1f", '$total_size' + '$size'}' ) - done - echo ${total_size} -} - -power_time() { - - result=$(smartctl -a $(result=$(cat /proc/mounts) && echo $(echo "$result" | awk '/data=ordered/{print $1}') | awk '{print $1}') 2>&1) && power_time=$(echo "$result" | awk '/Power_On/{print $10}') && echo "$power_time" -} - -install_smart() { - if [ ! -e '/usr/sbin/smartctl' ]; then - echo "Installing Smartctl ..." - if [ "${release}" == "centos" ]; then - yum update > /dev/null 2>&1 - yum -y install smartmontools > /dev/null 2>&1 - else - apt-get update > /dev/null 2>&1 - apt-get -y install smartmontools > /dev/null 2>&1 - fi - fi -} - -ip_info4(){ - ip_date=$(curl -4 -s http://api.ip.la/en?json) - echo $ip_date > ip_json.json - isp=$(python tools.py geoip isp) - as_tmp=$(python tools.py geoip as) - asn=$(echo $as_tmp | awk -F ' ' '{print $1}') - org=$(python tools.py geoip org) - if [ -z "ip_date" ]; then - echo $ip_date - echo "hala" - country=$(python tools.py ipip country_name) - city=$(python tools.py ipip city) - countryCode=$(python tools.py ipip country_code) - region=$(python tools.py ipip province) - else - country=$(python tools.py geoip country) - city=$(python tools.py geoip city) - countryCode=$(python tools.py geoip countryCode) - region=$(python tools.py geoip regionName) - fi - if [ -z "$city" ]; then - city=${region} - fi - - echo -e " ASN & ISP : ${SKYBLUE}$asn, $isp${PLAIN}" | tee -a $log - echo -e " Organization : ${YELLOW}$org${PLAIN}" | tee -a $log - echo -e " Location : ${SKYBLUE}$city, ${YELLOW}$country / $countryCode${PLAIN}" | tee -a $log - echo -e " Region : ${SKYBLUE}$region${PLAIN}" | tee -a $log - - rm -rf tools.py - rm -rf ip_json.json -} - -virt_check(){ - if hash ifconfig 2>/dev/null; then - eth=$(ifconfig) - fi - - virtualx=$(dmesg) 2>/dev/null - - if [ $(which dmidecode) ]; then - sys_manu=$(dmidecode -s system-manufacturer) 2>/dev/null - sys_product=$(dmidecode -s system-product-name) 2>/dev/null - sys_ver=$(dmidecode -s system-version) 2>/dev/null - else - sys_manu="" - sys_product="" - sys_ver="" - fi - - if grep docker /proc/1/cgroup -qa; then - virtual="Docker" - elif grep lxc /proc/1/cgroup -qa; then - virtual="Lxc" - elif grep -qa container=lxc /proc/1/environ; then - virtual="Lxc" - elif [[ -f /proc/user_beancounters ]]; then - virtual="OpenVZ" - elif [[ "$virtualx" == *kvm-clock* ]]; then - virtual="KVM" - elif [[ "$cname" == *KVM* ]]; then - virtual="KVM" - elif [[ "$virtualx" == *"VMware Virtual Platform"* ]]; then - virtual="VMware" - elif [[ "$virtualx" == *"Parallels Software International"* ]]; then - virtual="Parallels" - elif [[ "$virtualx" == *VirtualBox* ]]; then - virtual="VirtualBox" - elif [[ -e /proc/xen ]]; then - virtual="Xen" - elif [[ "$sys_manu" == *"Microsoft Corporation"* ]]; then - if [[ "$sys_product" == *"Virtual Machine"* ]]; then - if [[ "$sys_ver" == *"7.0"* || "$sys_ver" == *"Hyper-V" ]]; then - virtual="Hyper-V" - else - virtual="Microsoft Virtual Machine" - fi - fi - else - virtual="Dedicated" - fi -} - -power_time_check(){ - echo -ne " Power time of disk : " - install_smart - ptime=$(power_time) - echo -e "${SKYBLUE}$ptime Hours${PLAIN}" -} - -freedisk() { - freespace=$( df -m . | awk 'NR==2 {print $4}' ) - if [[ $freespace == "" ]]; then - $freespace=$( df -m . | awk 'NR==3 {print $3}' ) - fi - if [[ $freespace -gt 1024 ]]; then - printf "%s" $((1024*2)) - elif [[ $freespace -gt 512 ]]; then - printf "%s" $((512*2)) - elif [[ $freespace -gt 256 ]]; then - printf "%s" $((256*2)) - elif [[ $freespace -gt 128 ]]; then - printf "%s" $((128*2)) - else - printf "1" - fi -} - -print_io() { - if [[ $1 == "fast" ]]; then - writemb=$((128*2)) - else - writemb=$(freedisk) - fi - - writemb_size="$(( writemb / 2 ))MB" - if [[ $writemb_size == "1024MB" ]]; then - writemb_size="1.0GB" - fi - - if [[ $writemb != "1" ]]; then - echo -n " I/O Speed( $writemb_size ) : " | tee -a $log - io1=$( io_test $writemb ) - echo -e "${YELLOW}$io1${PLAIN}" | tee -a $log - echo -n " I/O Speed( $writemb_size ) : " | tee -a $log - io2=$( io_test $writemb ) - echo -e "${YELLOW}$io2${PLAIN}" | tee -a $log - echo -n " I/O Speed( $writemb_size ) : " | tee -a $log - io3=$( io_test $writemb ) - echo -e "${YELLOW}$io3${PLAIN}" | tee -a $log - ioraw1=$( echo $io1 | awk 'NR==1 {print $1}' ) - [ "`echo $io1 | awk 'NR==1 {print $2}'`" == "GB/s" ] && ioraw1=$( awk 'BEGIN{print '$ioraw1' * 1024}' ) - ioraw2=$( echo $io2 | awk 'NR==1 {print $1}' ) - [ "`echo $io2 | awk 'NR==1 {print $2}'`" == "GB/s" ] && ioraw2=$( awk 'BEGIN{print '$ioraw2' * 1024}' ) - ioraw3=$( echo $io3 | awk 'NR==1 {print $1}' ) - [ "`echo $io3 | awk 'NR==1 {print $2}'`" == "GB/s" ] && ioraw3=$( awk 'BEGIN{print '$ioraw3' * 1024}' ) - ioall=$( awk 'BEGIN{print '$ioraw1' + '$ioraw2' + '$ioraw3'}' ) - ioavg=$( awk 'BEGIN{printf "%.1f", '$ioall' / 3}' ) - echo -e " Average I/O Speed : ${YELLOW}$ioavg MB/s${PLAIN}" | tee -a $log - else - echo -e " ${RED}Not enough space!${PLAIN}" - fi -} - -print_system_info() { - echo -e " CPU Model : ${SKYBLUE}$cname${PLAIN}" | tee -a $log - echo -e " CPU Cores : ${YELLOW}$cores Cores ${SKYBLUE}@ $freq MHz $arch${PLAIN}" | tee -a $log - echo -e " CPU Cache : ${SKYBLUE}$corescache ${PLAIN}" | tee -a $log - echo -e " OS : ${SKYBLUE}$opsy ($lbit Bit) ${YELLOW}$virtual${PLAIN}" | tee -a $log - echo -e " Kernel : ${SKYBLUE}$kern${PLAIN}" | tee -a $log - echo -e " Total Space : ${SKYBLUE}$disk_used_size GB / ${YELLOW}$disk_total_size GB ${PLAIN}" | tee -a $log - echo -e " Total RAM : ${SKYBLUE}$uram MB / ${YELLOW}$tram MB ${SKYBLUE}($bram MB Buff)${PLAIN}" | tee -a $log - echo -e " Total SWAP : ${SKYBLUE}$uswap MB / $swap MB${PLAIN}" | tee -a $log - echo -e " Uptime : ${SKYBLUE}$up${PLAIN}" | tee -a $log - echo -e " Load Average : ${SKYBLUE}$load${PLAIN}" | tee -a $log - echo -e " TCP CC : ${YELLOW}$tcpctrl${PLAIN}" | tee -a $log -} - -print_end_time() { - end=$(date +%s) - time=$(( $end - $start )) - if [[ $time -gt 60 ]]; then - min=$(expr $time / 60) - sec=$(expr $time % 60) - echo -ne " Finished in : ${min} min ${sec} sec" | tee -a $log - else - echo -ne " Finished in : ${time} sec" | tee -a $log - fi - - printf '\n' | tee -a $log - - bj_time=$(curl -s http://cgi.im.qq.com/cgi-bin/cgi_svrtime) - - if [[ $(echo $bj_time | grep "html") ]]; then - bj_time=$(date -u +%Y-%m-%d" "%H:%M:%S -d '+8 hours') - fi - echo " Timestamp : $bj_time GMT+8" | tee -a $log - echo " Results : $log" -} - -get_system_info() { - cname=$( awk -F: '/model name/ {name=$2} END {print name}' /proc/cpuinfo | sed 's/^[ \t]*//;s/[ \t]*$//' ) - cores=$( awk -F: '/model name/ {core++} END {print core}' /proc/cpuinfo ) - freq=$( awk -F: '/cpu MHz/ {freq=$2} END {print freq}' /proc/cpuinfo | sed 's/^[ \t]*//;s/[ \t]*$//' ) - corescache=$( awk -F: '/cache size/ {cache=$2} END {print cache}' /proc/cpuinfo | sed 's/^[ \t]*//;s/[ \t]*$//' ) - tram=$( free -m | awk '/Mem/ {print $2}' ) - uram=$( free -m | awk '/Mem/ {print $3}' ) - bram=$( free -m | awk '/Mem/ {print $6}' ) - swap=$( free -m | awk '/Swap/ {print $2}' ) - uswap=$( free -m | awk '/Swap/ {print $3}' ) - up=$( awk '{a=$1/86400;b=($1%86400)/3600;c=($1%3600)/60} {printf("%d days %d hour %d min\n",a,b,c)}' /proc/uptime ) - load=$( w | head -1 | awk -F'load average:' '{print $2}' | sed 's/^[ \t]*//;s/[ \t]*$//' ) - opsy=$( get_opsy ) - arch=$( uname -m ) - lbit=$( getconf LONG_BIT ) - kern=$( uname -r ) - - disk_size1=($( LANG=C df -hPl | grep -wvE '\-|none|tmpfs|overlay|shm|udev|devtmpfs|by-uuid|chroot|Filesystem' | awk '{print $2}' )) - disk_size2=($( LANG=C df -hPl | grep -wvE '\-|none|tmpfs|overlay|shm|udev|devtmpfs|by-uuid|chroot|Filesystem' | awk '{print $3}' )) - disk_total_size=$( calc_disk ${disk_size1[@]} ) - disk_used_size=$( calc_disk ${disk_size2[@]} ) - - tcpctrl=$( sysctl net.ipv4.tcp_congestion_control | awk -F ' ' '{print $3}' ) - - virt_check -} - -print_intro() { - printf ' Superbench.sh -- https://www.oldking.net/350.html\n' | tee -a $log - printf " Mode : \e${GREEN}%s\e${PLAIN} Version : \e${GREEN}%s${PLAIN}\n" $mode_name 1.1.4 | tee -a $log - printf ' Usage : wget -qO- git.io/superbench.sh | bash\n' | tee -a $log -} - -sharetest() { - echo " Share result:" | tee -a $log - echo " · $result_speed" | tee -a $log - log_preupload - case $1 in - 'ubuntu') - share_link=$( curl -v --data-urlencode "content@$log_up" -d "poster=superbench.sh" -d "syntax=text" "https://paste.ubuntu.com" 2>&1 | \ - grep "Location" | awk '{print $3}' );; - 'haste' ) - share_link=$( curl -X POST -s -d "$(cat $log)" https://hastebin.com/documents | awk -F '"' '{print "https://hastebin.com/"$4}' );; - 'clbin' ) - share_link=$( curl -sF 'clbin=<-' https://clbin.com < $log );; - 'ptpb' ) - share_link=$( curl -sF c=@- https://ptpb.pw/?u=1 < $log );; - esac - - echo " · $share_link" | tee -a $log - next - echo "" - rm -f $log_up - -} - -log_preupload() { - log_up="$HOME/superbench_upload.log" - true > $log_up - $(cat superbench.log 2>&1 | sed -r "s/\x1B\[([0-9]{1,2}(;[0-9]{1,2})?)?[m|K]//g" > $log_up) -} - -cleanup() { - rm -f test_file_*; - rm -f speedtest.py; - rm -f fast_com*; - rm -f tools.py; - rm -f ip_json.json -} - -bench_all(){ - mode_name="Standard" - about; - benchinit; - clear - next; - print_intro; - next; - get_system_info; - print_system_info; - ip_info4; - next; - print_io; - next; - print_speedtest; - next; - print_end_time; - next; - cleanup; - sharetest ubuntu; -} - -fast_bench(){ - mode_name="Fast" - about; - benchinit; - clear - next; - print_intro; - next; - get_system_info; - print_system_info; - ip_info4; - next; - print_io fast; - next; - print_speedtest_fast; - next; - print_end_time; - next; - cleanup; -} - -log="$HOME/superbench.log" -true > $log - -case $1 in - 'info'|'-i'|'--i'|'-info'|'--info' ) - about;sleep 3;next;get_system_info;print_system_info;next;; - 'version'|'-v'|'--v'|'-version'|'--version') - next;about;next;; - 'io'|'-io'|'--io'|'-drivespeed'|'--drivespeed' ) - next;print_io;next;; - 'speed'|'-speed'|'--speed'|'-speedtest'|'--speedtest'|'-speedcheck'|'--speedcheck' ) - about;benchinit;next;print_speedtest;next;cleanup;; - 'ip'|'-ip'|'--ip'|'geoip'|'-geoip'|'--geoip' ) - about;benchinit;next;ip_info4;next;cleanup;; - 'bench'|'-a'|'--a'|'-all'|'--all'|'-bench'|'--bench' ) - bench_all;; - 'about'|'-about'|'--about' ) - about;; - 'fast'|'-f'|'--f'|'-fast'|'--fast' ) - fast_bench;; - 'share'|'-s'|'--s'|'-share'|'--share' ) - bench_all; - is_share="share" - if [[ $2 == "" ]]; then - sharetest ubuntu; - else - sharetest $2; - fi - ;; - 'debug'|'-d'|'--d'|'-debug'|'--debug' ) - get_ip_whois_org_name;; -*) - bench_all;; -esac - -if [[ ! $is_share == "share" ]]; then - case $2 in - 'share'|'-s'|'--s'|'-share'|'--share' ) - if [[ $3 == '' ]]; then - sharetest ubuntu; - else - sharetest $3; - fi - ;; - esac -fi \ No newline at end of file diff --git a/superbench_old.sh b/superbench_old.sh deleted file mode 100644 index c4fc6a5..0000000 --- a/superbench_old.sh +++ /dev/null @@ -1,272 +0,0 @@ -#!/usr/bin/env bash -# -# Description: Auto test download & I/O speed & network to China script -# -# Copyright (C) 2017 - 2017 Oldking -# -# Thanks: Bench.sh -# -# URL: https://www.oldking.net/350.html -# - -# Colors -RED='\033[0;31m' -GREEN='\033[0;32m' -YELLOW='\033[0;33m' -SKYBLUE='\033[0;36m' -PLAIN='\033[0m' - -# check release -if [ -f /etc/redhat-release ]; then - release="centos" -elif cat /etc/issue | grep -Eqi "debian"; then - release="debian" -elif cat /etc/issue | grep -Eqi "ubuntu"; then - release="ubuntu" -elif cat /etc/issue | grep -Eqi "centos|red hat|redhat"; then - release="centos" -elif cat /proc/version | grep -Eqi "debian"; then - release="debian" -elif cat /proc/version | grep -Eqi "ubuntu"; then - release="ubuntu" -elif cat /proc/version | grep -Eqi "centos|red hat|redhat"; then - release="centos" -fi - -# check root -[[ $EUID -ne 0 ]] && echo -e "${RED}Error:${PLAIN} This script must be run as root!" && exit 1 - -# check python -if [ ! -e '/usr/bin/python' ]; then - #echo -e - #read -p "${RED}Error:${PLAIN} python is not install. You must be install python command at first.\nDo you want to install? [y/n]" is_install - #if [[ ${is_install} == "y" || ${is_install} == "Y" ]]; then - if [ "${release}" == "centos" ]; then - yum update > /dev/null 2>&1 - yum -y install python - else - apt-get update > /dev/null 2>&1 - apt-get -y install python - fi - #else - # exit - #fi - -fi - -# check wget -if [ ! -e '/usr/bin/wget' ]; then - #echo -e - #read -p "${RED}Error:${PLAIN} wget is not install. You must be install wget command at first.\nDo you want to install? [y/n]" is_install - #if [[ ${is_install} == "y" || ${is_install} == "Y" ]]; then - if [ "${release}" == "centos" ]; then - yum update > /dev/null 2>&1 - yum -y install wget - else - apt-get update > /dev/null 2>&1 - apt-get -y install wget - fi - #else - # exit - #fi -fi - -get_opsy() { - [ -f /etc/redhat-release ] && awk '{print ($1,$3~/^[0-9]/?$3:$4)}' /etc/redhat-release && return - [ -f /etc/os-release ] && awk -F'[= "]' '/PRETTY_NAME/{print $3,$4,$5}' /etc/os-release && return - [ -f /etc/lsb-release ] && awk -F'[="]+' '/DESCRIPTION/{print $2}' /etc/lsb-release && return -} - -next() { - printf "%-70s\n" "-" | sed 's/\s/-/g' -} - -speed_test(){ - if [[ $1 == '' ]]; then - temp=$(python /tmp/speedtest.py --share 2>&1) - is_down=$(echo "$temp" | grep 'Download') - if [[ ${is_down} ]]; then - local REDownload=$(echo "$temp" | awk -F ':' '/Download/{print $2}') - local reupload=$(echo "$temp" | awk -F ':' '/Upload/{print $2}') - local relatency=$(echo "$temp" | awk -F ':' '/Hosted/{print $2}') - local nodeName=$2 - - printf "${YELLOW}%-17s${GREEN}%-18s${RED}%-20s${SKYBLUE}%-12s${PLAIN}\n" "${nodeName}" "${reupload}" "${REDownload}" "${relatency}" - else - local cerror="ERROR" - fi - else - temp=$(python /tmp/speedtest.py --server $1 --share 2>&1) - is_down=$(echo "$temp" | grep 'Download') - if [[ ${is_down} ]]; then - local REDownload=$(echo "$temp" | awk -F ':' '/Download/{print $2}') - local reupload=$(echo "$temp" | awk -F ':' '/Upload/{print $2}') - local relatency=$(echo "$temp" | awk -F ':' '/Hosted/{print $2}') - temp=$(echo "$relatency" | awk -F '.' '{print $1}') - if [[ ${temp} -gt 1000 ]]; then - relatency=" 000.000 ms" - fi - local nodeName=$2 - - printf "${YELLOW}%-17s${GREEN}%-18s${RED}%-20s${SKYBLUE}%-12s${PLAIN}\n" "${nodeName}" "${reupload}" "${REDownload}" "${relatency}" - else - local cerror="ERROR" - fi - fi -} - -speed() { - # install speedtest - if [ ! -e '/tmp/speedtest.py' ]; then - wget --no-check-certificate -P /tmp https://raw.github.com/sivel/speedtest-cli/master/speedtest.py > /dev/null 2>&1 - fi - chmod a+rx /tmp/speedtest.py - - speed_test '' 'Normal Node' - speed_test '6435' 'Xiangyang CT' - speed_test '7509' 'Kunming CT' - speed_test '3633' 'Shanghai CT' - speed_test '4624' 'Chengdu CT' - speed_test '5017' 'Shenyang CU' - speed_test '4863' "Xi'an CU" - speed_test '5083' 'Shanghai CU' - speed_test '5726' 'Chongqing CU' - speed_test '5292' "Xi'an CM" - speed_test '16314' 'Shandong CM' - speed_test '6715' 'Ningbo CM' - speed_test '4575' 'Chengdu CM' - - rm -rf /tmp/speedtest.py -} - - -io_test() { - (LANG=C dd if=/dev/zero of=test_$$ bs=$1 count=$2 conv=fdatasync && rm -f test_$$ ) 2>&1 | awk -F, '{io=$NF} END { print io}' | sed 's/^[ \t]*//;s/[ \t]*$//' -} - -calc_disk() { - local total_size=0 - local array=$@ - for size in ${array[@]} - do - [ "${size}" == "0" ] && size_t=0 || size_t=`echo ${size:0:${#size}-1}` - [ "`echo ${size:(-1)}`" == "K" ] && size=0 - [ "`echo ${size:(-1)}`" == "M" ] && size=$( awk 'BEGIN{printf "%.1f", '$size_t' / 1024}' ) - [ "`echo ${size:(-1)}`" == "T" ] && size=$( awk 'BEGIN{printf "%.1f", '$size_t' * 1024}' ) - [ "`echo ${size:(-1)}`" == "G" ] && size=${size_t} - total_size=$( awk 'BEGIN{printf "%.1f", '$total_size' + '$size'}' ) - done - echo ${total_size} -} - -power_time() { - - result=$(smartctl -a $(result=$(cat /proc/mounts) && echo $(echo "$result" | awk '/data=ordered/{print $1}') | awk '{print $1}') 2>&1) && power_time=$(echo "$result" | awk '/Power_On/{print $10}') && echo "$power_time" -} - -install_smart() { - # install smartctl - if [ ! -e '/usr/sbin/smartctl' ]; then - if [ "${release}" == "centos" ]; then - yum update > /dev/null 2>&1 - yum -y install smartmontools > /dev/null 2>&1 - else - apt-get update > /dev/null 2>&1 - apt-get -y install smartmontools > /dev/null 2>&1 - fi - fi -} - -start=$(date +%s) - -cname=$( awk -F: '/model name/ {name=$2} END {print name}' /proc/cpuinfo | sed 's/^[ \t]*//;s/[ \t]*$//' ) -cores=$( awk -F: '/model name/ {core++} END {print core}' /proc/cpuinfo ) -freq=$( awk -F: '/cpu MHz/ {freq=$2} END {print freq}' /proc/cpuinfo | sed 's/^[ \t]*//;s/[ \t]*$//' ) -tram=$( free -m | awk '/Mem/ {print $2}' ) -uram=$( free -m | awk '/Mem/ {print $3}' ) -swap=$( free -m | awk '/Swap/ {print $2}' ) -uswap=$( free -m | awk '/Swap/ {print $3}' ) -up=$( awk '{a=$1/86400;b=($1%86400)/3600;c=($1%3600)/60} {printf("%d days %d hour %d min\n",a,b,c)}' /proc/uptime ) -load=$( w | head -1 | awk -F'load average:' '{print $2}' | sed 's/^[ \t]*//;s/[ \t]*$//' ) -opsy=$( get_opsy ) -arch=$( uname -m ) -lbit=$( getconf LONG_BIT ) -kern=$( uname -r ) -ipv6=$( wget -qO- -t1 -T2 ipv6.icanhazip.com ) -disk_size1=($( LANG=C df -hPl | grep -wvE '\-|none|tmpfs|devtmpfs|by-uuid|chroot|Filesystem' | awk '{print $2}' )) -disk_size2=($( LANG=C df -hPl | grep -wvE '\-|none|tmpfs|devtmpfs|by-uuid|chroot|Filesystem' | awk '{print $3}' )) -disk_total_size=$( calc_disk ${disk_size1[@]} ) -disk_used_size=$( calc_disk ${disk_size2[@]} ) -ptime=$(power_time) - - -clear -next -echo -e "CPU model : ${SKYBLUE}$cname${PLAIN}" -echo -e "Number of cores : ${SKYBLUE}$cores${PLAIN}" -echo -e "CPU frequency : ${SKYBLUE}$freq MHz${PLAIN}" -echo -e "Total size of Disk : ${SKYBLUE}$disk_total_size GB ($disk_used_size GB Used)${PLAIN}" -echo -e "Total amount of Mem : ${SKYBLUE}$tram MB ($uram MB Used)${PLAIN}" -echo -e "Total amount of Swap : ${SKYBLUE}$swap MB ($uswap MB Used)${PLAIN}" -echo -e "System uptime : ${SKYBLUE}$up${PLAIN}" -echo -e "Load average : ${SKYBLUE}$load${PLAIN}" -echo -e "OS : ${SKYBLUE}$opsy${PLAIN}" -echo -e "Arch : ${SKYBLUE}$arch ($lbit Bit)${PLAIN}" -echo -e "Kernel : ${SKYBLUE}$kern${PLAIN}" -echo -ne "Virt : " - -# install virt-what -if [ ! -e '/usr/sbin/virt-what' ]; then - if [ "${release}" == "centos" ]; then - yum update > /dev/null 2>&1 - yum -y install virt-what > /dev/null 2>&1 - else - apt-get update > /dev/null 2>&1 - apt-get -y install virt-what > /dev/null 2>&1 - fi -fi -virtua=$(virt-what) 2>/dev/null - -if [[ ${virtua} ]]; then - echo -e "${SKYBLUE}$virtua${PLAIN}" -else - echo -e "${SKYBLUE}No Virt${PLAIN}" - echo -ne "Power time of disk : " - install_smart - echo -e "${SKYBLUE}$ptime Hours${PLAIN}" -fi -next -echo -n "I/O speed( 32M ) : " -io1=$( io_test 32k 1k ) -echo -e "${YELLOW}$io1${PLAIN}" -echo -n "I/O speed( 256M ) : " -io2=$( io_test 64k 4k ) -echo -e "${YELLOW}$io2${PLAIN}" -echo -n "I/O speed( 2G ) : " -io3=$( io_test 64k 32k ) -echo -e "${YELLOW}$io3${PLAIN}" -ioraw1=$( echo $io1 | awk 'NR==1 {print $1}' ) -[ "`echo $io1 | awk 'NR==1 {print $2}'`" == "GB/s" ] && ioraw1=$( awk 'BEGIN{print '$ioraw1' * 1024}' ) -ioraw2=$( echo $io2 | awk 'NR==1 {print $1}' ) -[ "`echo $io2 | awk 'NR==1 {print $2}'`" == "GB/s" ] && ioraw2=$( awk 'BEGIN{print '$ioraw2' * 1024}' ) -ioraw3=$( echo $io3 | awk 'NR==1 {print $1}' ) -[ "`echo $io3 | awk 'NR==1 {print $2}'`" == "GB/s" ] && ioraw3=$( awk 'BEGIN{print '$ioraw3' * 1024}' ) -ioall=$( awk 'BEGIN{print '$ioraw1' + '$ioraw2' + '$ioraw3'}' ) -ioavg=$( awk 'BEGIN{printf "%.1f", '$ioall' / 3}' ) -echo -e "Average I/O speed : ${YELLOW}$ioavg MB/s${PLAIN}" -next -printf "%-18s%-18s%-20s%-12s\n" "Node Name" "Upload Speed" "Download Speed" "Latency" -speed && next -end=$(date +%s) -time=$(( $end - $start )) -if [[ $time -gt 60 ]]; then - min=$(expr $time / 60) - sec=$(expr $time % 60) - echo -ne "Total time : ${min} min ${sec} sec" -else - echo -ne "Total time : ${time} sec" -fi -echo -ne "\nCurrent time : " -echo $(date +%Y-%m-%d" "%H:%M:%S) -echo "Finished!" -next \ No newline at end of file diff --git a/superspeed.sh b/superspeed.sh index 923f3e9..2d60cd0 100644 --- a/superspeed.sh +++ b/superspeed.sh @@ -1,431 +1,415 @@ #!/usr/bin/env bash -# -# Description: Test your server's network with Speedtest to China -# -# Copyright (C) 2017 - 2017 Oldking -# -# URL: https://www.oldking.net/305.html -# # Colors RED='\033[0;31m' GREEN='\033[0;32m' YELLOW='\033[0;33m' -SKYBLUE='\033[0;36m' +BLUE='\033[0;34m' +PURPLE="\033[0;35m" +CYAN='\033[0;36m' PLAIN='\033[0m' -# check root -[[ $EUID -ne 0 ]] && echo -e "${RED}Error:${PLAIN} This script must be run as root!" && exit 1 +checkroot(){ + [[ $EUID -ne 0 ]] && echo -e "${RED}请使用 root 用户运行本脚本!${PLAIN}" && exit 1 +} + +checksystem() { + if [ -f /etc/redhat-release ]; then + release="centos" + elif cat /etc/issue | grep -Eqi "debian"; then + release="debian" + elif cat /etc/issue | grep -Eqi "ubuntu"; then + release="ubuntu" + elif cat /etc/issue | grep -Eqi "centos|red hat|redhat"; then + release="centos" + elif cat /proc/version | grep -Eqi "debian"; then + release="debian" + elif cat /proc/version | grep -Eqi "ubuntu"; then + release="ubuntu" + elif cat /proc/version | grep -Eqi "centos|red hat|redhat"; then + release="centos" + fi +} + +checkpython() { + if [ ! -e '/usr/bin/python' ]; then + echo "正在安装 Python" + if [ "${release}" == "centos" ]; 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 + + fi +} -# check python -if [ ! -e '/usr/bin/python' ]; then - echo -e - read -p "${RED}Error:${PLAIN} python is not install. You must be install python command at first.\nDo you want to install? [y/n]" is_install - if [[ ${is_install} == "y" || ${is_install} == "Y" ]]; then - if [ "${release}" == "centos" ]; then - yum -y install python - else - apt-get -y install python - fi - else - exit - fi - -fi +checkcurl() { + if [ ! -e '/usr/bin/curl' ]; then + echo "正在安装 Curl" + if [ "${release}" == "centos" ]; 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 + fi +} -# check wget -if [ ! -e '/usr/bin/wget' ]; then - echo -e - read -p "${RED}Error:${PLAIN} wget is not install. You must be install wget command at first.\nDo you want to install? [y/n]" is_install - if [[ ${is_install} == "y" || ${is_install} == "Y" ]]; then - if [ "${release}" == "centos" ]; then - yum -y install wget - else - apt-get -y install wget - fi - else - exit - fi -fi +checkwget() { + if [ ! -e '/usr/bin/wget' ]; then + echo "正在安装 Wget" + if [ "${release}" == "centos" ]; 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 + fi +} + +checkspeedtest() { + if [ ! -e './speedtest-cli/speedtest' ]; then + echo "正在安装 Speedtest-cli" + wget --no-check-certificate -qO speedtest.tgz https://bintray.com/ookla/download/download_file?file_path=ookla-speedtest-1.0.0-$(uname -m)-linux.tgz > /dev/null 2>&1 + fi + mkdir -p speedtest-cli && tar zxvf speedtest.tgz -C ./speedtest-cli/ > /dev/null 2>&1 && chmod a+rx ./speedtest-cli/speedtest +} +speed_test(){ + speedLog="./speedtest.log" + true > $speedLog + speedtest-cli/speedtest -p no -s $1 --accept-license > $speedLog 2>&1 + 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 + #echo $LANG + + 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 +} -clear -echo "#############################################################" -echo "# Description: Test your server's network with Speedtest #" -echo "# Intro: https://www.oldking.net/305.html #" -echo "# Author: Oldking #" -echo "# Github: https://github.com/oooldking #" -echo "#############################################################" -echo -echo "测试服务器到" -echo -ne "1.中国电信 2.中国联通 3.中国移动 4.本地默认 5.全面测速" +preinfo() { + echo "———————————————————SuperSpeed 全面测速版——————————————————" + echo " bash <(curl -Lso- https://git.io/superspeed)" + echo " 全部节点列表: https://git.io/superspeedList" + echo " 节点更新: 2020/04/09 | 脚本更新: 2020/04/09" + echo "——————————————————————————————————————————————————————————" +} -while :; do echo - read -p "请输入数字选择: " telecom - if [[ ! $telecom =~ ^[1-5]$ ]]; then - echo "输入错误! 请输入正确的数字!" - else - break - fi -done +selecttest() { + echo -e " 测速类型: ${GREEN}1.${PLAIN} 三网测速 ${GREEN}2.${PLAIN} 取消测速" + echo -ne " ${GREEN}3.${PLAIN} 电信节点 ${GREEN}4.${PLAIN} 联通节点 ${GREEN}5.${PLAIN} 移动节点" + while :; do echo + read -p " 请输入数字选择测速类型: " selection + if [[ ! $selection =~ ^[1-5]$ ]]; then + echo -ne " ${RED}输入错误${PLAIN}, 请输入正确的数字!" + else + break + fi + done +} -if [[ ${telecom} == 1 ]]; then - telecomName="电信" - echo -e "\n选择最靠近你的方位" - echo -ne "1.北方 2.南方" - while :; do echo - read -p "请输入数字选择: " pos - if [[ ! $pos =~ ^[1-2]$ ]]; then - echo "输入错误! 请输入正确的数字!" - else - break - fi - done - echo -e "\n选择最靠近你的城市" - if [[ ${pos} == 1 ]]; then - echo -ne "1.郑州 2.襄阳" - while :; do echo - read -p "请输入数字选择: " city - if [[ ! $city =~ ^[1-2]$ ]]; then - echo "输入错误! 请输入正确的数字!" - else - break - fi - done - if [[ ${city} == 1 ]]; then - num=4595 - cityName="郑州" - fi - if [[ ${city} == 2 ]]; then - num=12637 - cityName="襄阳" - fi - fi - if [[ ${pos} == 2 ]]; then - echo -ne "1.上海 2.杭州 3.南宁 4.南昌 5.长沙 6.深圳 7.重庆 8.成都" - while :; do echo - read -p "请输入数字选择: " city - if [[ ! $city =~ ^[1-8]$ ]]; then - echo "输入错误! 请输入正确的数字!" - else - break - fi - done - if [[ ${city} == 1 ]]; then - num=3633 - cityName="上海" - fi - if [[ ${city} == 2 ]]; then - num=7509 - cityName="杭州" - fi - if [[ ${city} == 3 ]]; then - num=10305 - cityName="南宁" - fi - if [[ ${city} == 4 ]]; then - num=7230 - cityName="南昌" - fi - if [[ ${city} == 5 ]]; then - num=6132 - cityName="长沙" - fi - if [[ ${city} == 6 ]]; then - num=5081 - cityName="深圳" - fi - if [[ ${city} == 7 ]]; then - num=6592 - cityName="重庆" - fi - if [[ ${city} == 8 ]]; then - num=4624 - cityName="成都" - fi - fi -fi +runtest() { + [[ ${selection} == 2 ]] && exit 1 -if [[ ${telecom} == 2 ]]; then - telecomName="联通" - echo -ne "\n1.北方 2.南方" - while :; do echo - read -p "请输入数字选择: " pos - if [[ ! $pos =~ ^[1-2]$ ]]; then - echo "输入错误! 请输入正确的数字!" - else - break - fi - done - echo -e "\n选择最靠近你的城市" - if [[ ${pos} == 1 ]]; then - echo -ne "1.沈阳 2.长春 3.哈尔滨 4.天津 5.济南 6.北京 7.郑州 8.西安 9.太原 10.宁夏 11.兰州 12.西宁" - while :; do echo - read -p "请输入数字选择: " city - if [[ ! $city =~ ^(([1-9])|(1([0-2]{1})))$ ]]; then - echo "输入错误! 请输入正确的数字!" - else - break - fi - done - if [[ ${city} == 1 ]]; then - num=5017 - cityName="沈阳" - fi - if [[ ${city} == 2 ]]; then - num=9484 - cityName="长春" - fi - if [[ ${city} == 3 ]]; then - num=5460 - cityName="哈尔滨" - fi - if [[ ${city} == 4 ]]; then - num=5475 - cityName="天津" - fi - if [[ ${city} == 5 ]]; then - num=5039 - cityName="济南" - fi - if [[ ${city} == 6 ]]; then - num=5145 - cityName="北京" - fi - if [[ ${city} == 7 ]]; then - num=5131 - cityName="郑州" - fi - if [[ ${city} == 8 ]]; then - num= 4863 - cityName="西安" - fi - if [[ ${city} == 9 ]]; then - num=12868 - cityName="太原" - fi - if [[ ${city} == 10 ]]; then - num=5509 - cityName="宁夏" - fi - if [[ ${city} == 11 ]]; then - num=4690 - cityName="兰州" - fi - if [[ ${city} == 12 ]]; then - num=5992 - cityName="西宁" - fi - fi - if [[ ${pos} == 2 ]]; then - echo -ne "1.上海 2.杭州 3.南宁 4.合肥 5.南昌 6.长沙 7.深圳 8.广州 9.重庆 10.昆明 11.成都" - while :; do echo - read -p "请输入数字选择: " city - if [[ ! $city =~ ^(([1-9])|(1([0-1]{1})))$ ]]; then - echo "输入错误! 请输入正确的数字!" - else - break - fi - done - if [[ ${city} == 1 ]]; then - num=5083 - cityName="上海" - fi - if [[ ${city} == 2 ]]; then - num=5300 - cityName="杭州" - fi - if [[ ${city} == 3 ]]; then - num=5674 - cityName="南宁" - fi - if [[ ${city} == 4 ]]; then - num=5724 - cityName="合肥" - fi - if [[ ${city} == 5 ]]; then - num=5079 - cityName="南昌" - fi - if [[ ${city} == 6 ]]; then - num=4870 - cityName="长沙" - fi - if [[ ${city} == 7 ]]; then - num=10201 - cityName="深圳" - fi - if [[ ${city} == 8 ]]; then - num=3891 - cityName="广州" - fi - if [[ ${city} == 9 ]]; then - num=5726 - cityName="重庆" - fi - if [[ ${city} == 10 ]]; then - num=5103 - cityName="昆明" - fi - if [[ ${city} == 11 ]]; then - num=2461 - cityName="成都" - fi - fi -fi + if [[ ${selection} == 1 ]]; then + echo "——————————————————————————————————————————————————————————" + echo "ID 测速服务器信息 上传/Mbps 下载/Mbps 延迟/ms" + start=$(date +%s) -if [[ ${telecom} == 3 ]]; then - telecomName="移动" - echo -ne "\n1.北方 2.南方" - while :; do echo - read -p "请输入数字选择: " pos - if [[ ! $pos =~ ^[1-2]$ ]]; then - echo "输入错误! 请输入正确的数字!" - else - break - fi - done - echo -e "\n选择最靠近你的城市" - if [[ ${pos} == 1 ]]; then - echo -ne "1.西安" - while :; do echo - read -p "请输入数字选择: " city - if [[ ! $city =~ ^[1]$ ]]; then - echo "输入错误! 请输入正确的数字!" - else - break - fi - done - if [[ ${city} == 1 ]]; then - num=5292 - fi - fi - if [[ ${pos} == 2 ]]; then - echo -ne "1.上海 2.宁波 3.无锡 4.杭州 5.合肥 6.成都" - while :; do echo - read -p "请输入数字选择: " city - if [[ ! $city =~ ^[1-6]$ ]]; then - echo "输入错误! 请输入正确的数字!" - else - break - fi - done - if [[ ${city} == 1 ]]; then - num=4665 - cityName="上海" - fi - if [[ ${city} == 2 ]]; then - num=6715 - cityName="宁波" - fi - if [[ ${city} == 3 ]]; then - num=5122 - cityName="无锡" - fi - if [[ ${city} == 4 ]]; then - num=4647 - cityName="杭州" - fi - if [[ ${city} == 5 ]]; then - num=4377 - cityName="合肥" - fi - if [[ ${city} == 6 ]]; then - num=4575 - cityName="成都" - fi - fi -fi + speed_test '3633' '上海' '电信' + speed_test '24012' '内蒙古呼和浩特' '电信' + speed_test '27377' '北京5G' '电信' + speed_test '29026' '四川成都' '电信' + # speed_test '29071' '四川成都' '电信' + speed_test '17145' '安徽合肥5G' '电信' + speed_test '27594' '广东广州5G' '电信' + # speed_test '27810' '广西南宁' '电信' + speed_test '27575' '新疆乌鲁木齐' '电信' + # speed_test '26352' '江苏南京5G' '电信' + speed_test '5396' '江苏苏州5G' '电信' + # speed_test '5317' '江苏连云港5G' '电信' + # speed_test '7509' '浙江杭州' '电信' + speed_test '23844' '湖北武汉' '电信' + speed_test '29353' '湖北武汉5G' '电信' + speed_test '28225' '湖南长沙5G' '电信' + speed_test '3973' '甘肃兰州' '电信' + # speed_test '19076' '重庆' '电信' + #*** + # speed_test '21005' '上海' '联通' + speed_test '24447' '上海5G' '联通' + # speed_test '5103' '云南昆明' '联通' + speed_test '5145' '北京' '联通' + # speed_test '5505' '北京' '联通' + # speed_test '9484' '吉林长春' '联通' + speed_test '2461' '四川成都' '联通' + speed_test '27154' '天津5G' '联通' + # speed_test '5509' '宁夏银川' '联通' + # speed_test '5724' '安徽合肥' '联通' + # speed_test '5039' '山东济南' '联通' + speed_test '26180' '山东济南5G' '联通' + speed_test '26678' '广东广州5G' '联通' + # speed_test '16192' '广东深圳' '联通' + # speed_test '6144' '新疆乌鲁木齐' '联通' + speed_test '13704' '江苏南京' '联通' + speed_test '5485' '湖北武汉' '联通' + # speed_test '26677' '湖南株洲' '联通' + speed_test '4870' '湖南长沙' '联通' + # speed_test '4690' '甘肃兰州' '联通' + # speed_test '4884' '福建福州' '联通' + # speed_test '31985' '重庆' '联通' + speed_test '4863' '陕西西安' '联通' + #*** + # speed_test '30154' '上海' '移动' + # speed_test '25637' '上海5G' '移动' + # speed_test '26728' '云南昆明' '移动' + # speed_test '27019' '内蒙古呼和浩特' '移动' + speed_test '30232' '内蒙呼和浩特5G' '移动' + # speed_test '30293' '内蒙古通辽5G' '移动' + speed_test '25858' '北京' '移动' + speed_test '16375' '吉林长春' '移动' + # speed_test '24337' '四川成都' '移动' + speed_test '17184' '天津5G' '移动' + # speed_test '26940' '宁夏银川' '移动' + # speed_test '31815' '宁夏银川' '移动' + # speed_test '26404' '安徽合肥5G' '移动' + speed_test '27151' '山东临沂5G' '移动' + # speed_test '25881' '山东济南5G' '移动' + # speed_test '27100' '山东青岛5G' '移动' + # speed_test '26501' '山西太原5G' '移动' + speed_test '31520' '广东中山' '移动' + # speed_test '6611' '广东广州' '移动' + # speed_test '4515' '广东深圳' '移动' + # speed_test '15863' '广西南宁' '移动' + # speed_test '16858' '新疆乌鲁木齐' '移动' + speed_test '26938' '新疆乌鲁木齐5G' '移动' + # speed_test '17227' '新疆和田' '移动' + # speed_test '17245' '新疆喀什' '移动' + # speed_test '17222' '新疆阿勒泰' '移动' + # speed_test '27249' '江苏南京5G' '移动' + # speed_test '21845' '江苏常州5G' '移动' + # speed_test '26850' '江苏无锡5G' '移动' + # speed_test '17320' '江苏镇江5G' '移动' + speed_test '25883' '江西南昌5G' '移动' + # speed_test '17223' '河北石家庄' '移动' + # speed_test '26331' '河南郑州5G' '移动' + # speed_test '6715' '浙江宁波5G' '移动' + # speed_test '4647' '浙江杭州' '移动' + # speed_test '16503' '海南海口' '移动' + # speed_test '28491' '湖南长沙5G' '移动' + # speed_test '16145' '甘肃兰州' '移动' + speed_test '16171' '福建福州' '移动' + # speed_test '18444' '西藏拉萨' '移动' + speed_test '16398' '贵州贵阳' '移动' + speed_test '25728' '辽宁大连' '移动' + # speed_test '16167' '辽宁沈阳' '移动' + # speed_test '17584' '重庆' '移动' + # speed_test '26380' '陕西西安' '移动' + # speed_test '29105' '陕西西安5G' '移动' + # speed_test '29083' '青海西宁5G' '移动' + # speed_test '26656' '黑龙江哈尔滨' '移动' -# install speedtest -if [ ! -e '/tmp/speedtest.py' ]; then - wget --no-check-certificate -P /tmp https://raw.github.com/sivel/speedtest-cli/master/speedtest.py > /dev/null 2>&1 -fi -chmod a+rx /tmp/speedtest.py + end=$(date +%s) + rm -rf speedtest* + echo "——————————————————————————————————————————————————————————" + time=$(( $end - $start )) + if [[ $time -gt 60 ]]; then + min=$(expr $time / 60) + sec=$(expr $time % 60) + echo -ne " 测试完成, 本次测速耗时: ${min} 分 ${sec} 秒" + else + echo -ne " 测试完成, 本次测速耗时: ${time} 秒" + fi + echo -ne "\n 当前时间: " + echo $(date +%Y-%m-%d" "%H:%M:%S) + echo -e " ${GREEN}# 三网测速中为避免节点数不均及测试过久,每部分未使用所${PLAIN}" + echo -e " ${GREEN}# 有节点,如果需要使用全部节点,可分别选择三网节点检测${PLAIN}" + fi -result() { - download=`cat /tmp/speed.log | awk -F ':' '/Download/{print $2}'` - upload=`cat /tmp/speed.log | awk -F ':' '/Upload/{print $2}'` - hostby=`cat /tmp/speed.log | awk -F ':' '/Hosted/{print $1}'` - latency=`cat /tmp/speed.log | awk -F ':' '/Hosted/{print $2}'` - clear - echo "$hostby" - echo "延迟 : $latency" - echo "上传 : $upload" - echo "下载 : $download" - echo -ne "\n当前时间: " - echo $(date +%Y-%m-%d" "%H:%M:%S) -} + if [[ ${selection} == 3 ]]; then + echo "——————————————————————————————————————————————————————————" + echo "ID 测速服务器信息 上传/Mbps 下载/Mbps 延迟/ms" + start=$(date +%s) -speed_test(){ - temp=$(python /tmp/speedtest.py --server $1 --share 2>&1) - is_down=$(echo "$temp" | grep 'Download') - if [[ ${is_down} ]]; then - local REDownload=$(echo "$temp" | awk -F ':' '/Download/{print $2}') - local reupload=$(echo "$temp" | awk -F ':' '/Upload/{print $2}') - local relatency=$(echo "$temp" | awk -F ':' '/Hosted/{print $2}') - temp=$(echo "$relatency" | awk -F '.' '{print $1}') - if [[ ${temp} -gt 1000 ]]; then - relatency=" 000.000 ms" - fi - local nodeName=$2 + speed_test '3633' '上海' '电信' + speed_test '24012' '内蒙古呼和浩特' '电信' + speed_test '27377' '北京5G' '电信' + speed_test '29026' '四川成都' '电信' + speed_test '29071' '四川成都' '电信' + speed_test '17145' '安徽合肥5G' '电信' + speed_test '27594' '广东广州5G' '电信' + speed_test '27810' '广西南宁' '电信' + speed_test '27575' '新疆乌鲁木齐' '电信' + speed_test '26352' '江苏南京5G' '电信' + speed_test '5396' '江苏苏州5G' '电信' + speed_test '5317' '江苏连云港5G' '电信' + speed_test '7509' '浙江杭州' '电信' + speed_test '23844' '湖北武汉' '电信' + speed_test '29353' '湖北武汉5G' '电信' + speed_test '28225' '湖南长沙5G' '电信' + speed_test '3973' '甘肃兰州' '电信' + speed_test '19076' '重庆' '电信' - printf "${YELLOW}%-17s${GREEN}%-18s${RED}%-20s${SKYBLUE}%-12s${PLAIN}\n" "${nodeName}" "${reupload}" "${REDownload}" "${relatency}" - else - local cerror="ERROR" + end=$(date +%s) + rm -rf speedtest* + echo "——————————————————————————————————————————————————————————" + time=$(( $end - $start )) + if [[ $time -gt 60 ]]; then + min=$(expr $time / 60) + sec=$(expr $time % 60) + echo -ne " 测试完成, 本次测速耗时: ${min} 分 ${sec} 秒" + else + echo -ne " 测试完成, 本次测速耗时: ${time} 秒" + fi + echo -ne "\n 当前时间: " + echo $(date +%Y-%m-%d" "%H:%M:%S) fi -} -if [[ ${telecom} =~ ^[1-3]$ ]]; then - python /tmp/speedtest.py --server ${num} --share 2>/dev/null | tee /tmp/speed.log 2>/dev/null - is_down=$(cat /tmp/speed.log | grep 'Download') + if [[ ${selection} == 4 ]]; then + echo "——————————————————————————————————————————————————————————" + echo "ID 测速服务器信息 上传/Mbps 下载/Mbps 延迟/ms" + start=$(date +%s) + + speed_test '21005' '上海' '联通' + speed_test '24447' '上海5G' '联通' + speed_test '5103' '云南昆明' '联通' + speed_test '5145' '北京' '联通' + speed_test '5505' '北京' '联通' + speed_test '9484' '吉林长春' '联通' + speed_test '2461' '四川成都' '联通' + speed_test '27154' '天津5G' '联通' + speed_test '5509' '宁夏银川' '联通' + speed_test '5724' '安徽合肥' '联通' + speed_test '5039' '山东济南' '联通' + speed_test '26180' '山东济南5G' '联通' + speed_test '26678' '广东广州5G' '联通' + speed_test '16192' '广东深圳' '联通' + speed_test '6144' '新疆乌鲁木齐' '联通' + speed_test '13704' '江苏南京' '联通' + speed_test '5485' '湖北武汉' '联通' + speed_test '26677' '湖南株洲' '联通' + speed_test '4870' '湖南长沙' '联通' + speed_test '4690' '甘肃兰州' '联通' + speed_test '4884' '福建福州' '联通' + speed_test '31985' '重庆' '联通' + speed_test '4863' '陕西西安' '联通' - if [[ ${is_down} ]]; then - result - echo "测试到 ${cityName}${telecomName} 完成!" - rm -rf /tmp/speedtest.py - rm -rf /tmp/speed.log - else - echo -e "\n${RED}ERROR:${PLAIN} 当前节点不可用,请更换其他节点,或换个时间段再测试。" + end=$(date +%s) + rm -rf speedtest* + echo "——————————————————————————————————————————————————————————" + time=$(( $end - $start )) + if [[ $time -gt 60 ]]; then + min=$(expr $time / 60) + sec=$(expr $time % 60) + echo -ne " 测试完成, 本次测速耗时: ${min} 分 ${sec} 秒" + else + echo -ne " 测试完成, 本次测速耗时: ${time} 秒" + fi + echo -ne "\n 当前时间: " + echo $(date +%Y-%m-%d" "%H:%M:%S) fi -fi -if [[ ${telecom} == 4 ]]; then - python /tmp/speedtest.py | tee /tmp/speed.log - result - echo "本地测试完成!" - rm -rf /tmp/speedtest.py - rm -rf /tmp/speed.log -fi + if [[ ${selection} == 5 ]]; then + echo "——————————————————————————————————————————————————————————" + echo "ID 测速服务器信息 上传/Mbps 下载/Mbps 延迟/ms" + start=$(date +%s) -if [[ ${telecom} == 5 ]]; then - echo "" - printf "%-14s%-18s%-20s%-12s\n" "Node Name" "Upload Speed" "Download Speed" "Latency" - start=$(date +%s) - speed_test '6435' '襄阳电信' - speed_test '7509' '昆明电信' - speed_test '3633' '上海电信' - speed_test '4624' '成都电信' - speed_test '5017' '沈阳联通' - speed_test '4863' '西安联通' - speed_test '5083' '上海联通' - speed_test '5726' '重庆联通' - speed_test '5292' '西安移动' - speed_test '16314' '山东移动' - speed_test '6715' '宁波移动' - speed_test '4575' '成都移动' - end=$(date +%s) - rm -rf /tmp/speedtest.py - echo "" - time=$(( $end - $start )) - if [[ $time -gt 60 ]]; then - min=$(expr $time / 60) - sec=$(expr $time % 60) - echo -ne "花费时间:${min} 分 ${sec} 秒" - else - echo -ne "花费时间:${time} 秒" + speed_test '30154' '上海' '移动' + speed_test '25637' '上海5G' '移动' + speed_test '26728' '云南昆明' '移动' + speed_test '27019' '内蒙古呼和浩特' '移动' + speed_test '30232' '内蒙呼和浩特5G' '移动' + speed_test '30293' '内蒙古通辽5G' '移动' + speed_test '25858' '北京' '移动' + speed_test '16375' '吉林长春' '移动' + speed_test '24337' '四川成都' '移动' + speed_test '17184' '天津5G' '移动' + speed_test '26940' '宁夏银川' '移动' + speed_test '31815' '宁夏银川' '移动' + speed_test '26404' '安徽合肥5G' '移动' + speed_test '27151' '山东临沂5G' '移动' + speed_test '25881' '山东济南5G' '移动' + speed_test '27100' '山东青岛5G' '移动' + speed_test '26501' '山西太原5G' '移动' + speed_test '31520' '广东中山' '移动' + speed_test '6611' '广东广州' '移动' + speed_test '4515' '广东深圳' '移动' + speed_test '15863' '广西南宁' '移动' + speed_test '16858' '新疆乌鲁木齐' '移动' + speed_test '26938' '新疆乌鲁木齐5G' '移动' + speed_test '17227' '新疆和田' '移动' + speed_test '17245' '新疆喀什' '移动' + speed_test '17222' '新疆阿勒泰' '移动' + speed_test '27249' '江苏南京5G' '移动' + speed_test '21845' '江苏常州5G' '移动' + speed_test '26850' '江苏无锡5G' '移动' + speed_test '17320' '江苏镇江5G' '移动' + speed_test '25883' '江西南昌5G' '移动' + speed_test '17223' '河北石家庄' '移动' + speed_test '26331' '河南郑州5G' '移动' + speed_test '6715' '浙江宁波5G' '移动' + speed_test '4647' '浙江杭州' '移动' + speed_test '16503' '海南海口' '移动' + speed_test '28491' '湖南长沙5G' '移动' + speed_test '16145' '甘肃兰州' '移动' + speed_test '16171' '福建福州' '移动' + speed_test '18444' '西藏拉萨' '移动' + speed_test '16398' '贵州贵阳' '移动' + speed_test '25728' '辽宁大连' '移动' + speed_test '16167' '辽宁沈阳' '移动' + speed_test '17584' '重庆' '移动' + speed_test '26380' '陕西西安' '移动' + speed_test '29105' '陕西西安5G' '移动' + speed_test '29083' '青海西宁5G' '移动' + speed_test '26656' '黑龙江哈尔滨' '移动' + + end=$(date +%s) + rm -rf speedtest* + echo "——————————————————————————————————————————————————————————" + time=$(( $end - $start )) + if [[ $time -gt 60 ]]; then + min=$(expr $time / 60) + sec=$(expr $time % 60) + echo -ne " 测试完成, 本次测速耗时: ${min} 分 ${sec} 秒" + else + echo -ne " 测试完成, 本次测速耗时: ${time} 秒" + fi + echo -ne "\n 当前时间: " + echo $(date +%Y-%m-%d" "%H:%M:%S) fi - echo -ne "\n当前时间: " - echo $(date +%Y-%m-%d" "%H:%M:%S) - echo "全面测试完成!" -fi +} + +runall() { + checkroot; + checksystem; + checkpython; + checkcurl; + checkwget; + checkspeedtest; + clear + speed_test; + preinfo; + selecttest; + runtest; + rm -rf speedtest* +} + +runall diff --git a/superupdate.sh b/superupdate.sh deleted file mode 100644 index d04830d..0000000 --- a/superupdate.sh +++ /dev/null @@ -1,217 +0,0 @@ -#!/usr/bin/env bash -# -# Description: Choose a faster mirror for Linux script -# -# Copyright (C) 2017 - 2018 Oldking -# -# URL: https://www.oldking.net/697.html -# - -RED='\033[0;31m' -GREEN='\033[0;32m' -YELLOW='\033[0;33m' -SKYBLUE='\033[0;36m' -PLAIN='\033[0m' - -getAbout() { - echo "" - echo " ========================================================= " - echo " \ SuperUpdate.sh Script / " - echo " \ Choose a faster mirror for Linux / " - echo " \ Created by Oldking / " - echo " ========================================================= " - echo "" - echo " Intro: https://www.oldking.net/697.html" - echo " Copyright (C) 2018 Oldking oooldking@gmail.com" - echo -e " Version: ${GREEN}1.0.3${PLAIN} (2 Nov 2018)" - echo " Usage: wget -qO- git.io/superupdate.sh | bash" - echo "" -} - -getHelp(){ - echo " $( bash superupdate.sh )" - ehco " - set sources from cdn-fastly " - echo " $( bash superupdate.sh cn ) " - echo " - set sources from USTC " - echo " $( bash superupdate.sh 163 ) " - echo " - set sources from 163.com " - echo " $( bash superupdate.sh aliyun ) " - echo " - set sources from aliyun.com " - echo " $( bash superupdate.sh aws ) " - echo " - set sources from cdn-aws " - echo " $( bash superupdate.sh restore ) " - echo " - restore sources from backup file " -} - -updateInit(){ - [[ $EUID -ne 0 ]] && echo -e " ${RED}Error:${PLAIN} This script must be run as root!" && exit 1 - - if [ -f /etc/redhat-release ]; then - release="centos" - elif cat /etc/issue | grep -Eqi "debian"; then - release="debian" - elif cat /etc/issue | grep -Eqi "ubuntu"; then - release="ubuntu" - elif cat /etc/issue | grep -Eqi "centos|red hat|redhat"; then - release="centos" - elif cat /proc/version | grep -Eqi "debian"; then - release="debian" - elif cat /proc/version | grep -Eqi "ubuntu"; then - release="ubuntu" - elif cat /proc/version | grep -Eqi "centos|red hat|redhat"; then - release="centos" - fi - - if [ $release == "debian" ]; then - debianVersion=$(awk -F'[= "]' '/VERSION_ID/{print $3}' /etc/os-release) - elif [ $release == "ubuntu" ]; then - ubuntuVersion=$(awk -F'[= "]' '/VERSION_ID/{print $3}' /etc/os-release) - elif [ $release == "centos" ]; then - os_release=$(grep "CentOS" /etc/redhat-release 2>/dev/null) - if echo "$os_release"|grep "release 5" >/dev/null 2>&1 - then - centosVersion=5 - elif echo "$os_release"|grep "release 6" >/dev/null 2>&1 - then - centosVersion=6 - elif echo "$os_release"|grep "release 7" >/dev/null 2>&1 - then - centosVersion=7 - else - centosVersion="" - fi - else - echo -e " ${RED}Error:${PLAIN} This script can not be run in your system now!" && exit 1 - fi -} - -setDebian(){ - if [[ -f /etc/apt/sources.list.bak ]]; then - echo -e " ${GREEN}sources.list.bak exists${PLAIN}" - else - mv /etc/apt/sources.list{,.bak} - fi - - [ -f /etc/apt/sources.list ] && rm /etc/apt/sources.list - - echo "deb http://cdn-fastly.deb.debian.org/debian/ jessie main non-free contrib" >>/etc/apt/sources.list - echo "deb http://cdn-fastly.deb.debian.org/debian/ jessie-updates main non-free contrib" >>/etc/apt/sources.list - echo "deb http://cdn-fastly.deb.debian.org/debian/ jessie-backports main non-free contrib" >>/etc/apt/sources.list - echo "deb-src http://cdn-fastly.deb.debian.org/debian/ jessie main non-free contrib" >>/etc/apt/sources.list - echo "deb-src http://cdn-fastly.deb.debian.org/debian/ jessie-updates main non-free contrib" >>/etc/apt/sources.list - echo "deb-src http://cdn-fastly.deb.debian.org/debian/ jessie-backports main non-free contrib" >>/etc/apt/sources.list - echo "deb http://cdn-fastly.deb.debian.org/debian-security/ jessie/updates main non-free contrib" >>/etc/apt/sources.list - echo "deb-src http://cdn-fastly.deb.debian.org/debian-security/ jessie/updates main non-free contrib" >>/etc/apt/sources.list - - [ "$debianVersion" == '7' ] && sed -i 's/jessie/wheezy/'g /etc/apt/sources.list - [ "$debianVersion" == '8' ] && echo -n "" - [ "$debianVersion" == '9' ] && sed -i 's/jessie/stretch/'g /etc/apt/sources.list -} - -setUbuntu(){ - if [[ -f /etc/apt/sources.list.bak ]]; then - echo -e " ${GREEN}sources.list.bak exists${PLAIN}" - else - mv /etc/apt/sources.list{,.bak} - fi - - [ -f /etc/apt/sources.list ] && rm /etc/apt/sources.list - - echo "deb http://mirrors.aliyun.com/ubuntu/ xenial main restricted universe multiverse" >>/etc/apt/sources.list - echo "deb http://mirrors.aliyun.com/ubuntu/ xenial-security main restricted universe multiverse" >>/etc/apt/sources.list - echo "deb http://mirrors.aliyun.com/ubuntu/ xenial-updates main restricted universe multiverse" >>/etc/apt/sources.list - echo "deb http://mirrors.aliyun.com/ubuntu/ xenial-backports main restricted universe multiverse" >>/etc/apt/sources.list - echo "deb-src http://mirrors.aliyun.com/ubuntu/ xenial main restricted universe multiverse" >>/etc/apt/sources.list - echo "deb-src http://mirrors.aliyun.com/ubuntu/ xenial-security main restricted universe multiverse" >>/etc/apt/sources.list - echo "deb-src http://mirrors.aliyun.com/ubuntu/ xenial-updates main restricted universe multiverse" >>/etc/apt/sources.list - echo "deb-src http://mirrors.aliyun.com/ubuntu/ xenial-backports main restricted universe multiverse" >>/etc/apt/sources.list - - [ "$ubuntuVersion" == '14.04' ] && sed -i 's/xenial/trusty/'g /etc/apt/sources.list - [ "$ubuntuVersion" == '16.06' ] && echo -n "" - [ "$ubuntuVersion" == '18.04' ] && sed -i 's/xenial/bionic/'g /etc/apt/sources.list -} - -setCentos(){ - if [ -f /etc/yum.repos.d/CentOS-Base.repo.bak ]; then - echo -e " ${GREEN}CentOS-Base.repo.bak exists${PLAIN}" - else - mv /etc/yum.repos.d/CentOS-Base.repo{,.bak} - fi - - [ -f /etc/yum.repos.d/CentOS-Base.repo ] && rm /etc/yum.repos.d/CentOS-Base.repo - - [ "$centosVersion" == '5' ] && wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-5.repo - [ "$centosVersion" == '6' ] && wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-6.repo - [ "$centosVersion" == '7' ] && wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo -} - -setAWS(){ - sed -i 's/cdn-fastly.deb.debian.org/cdn-aws.deb.debian.org/'g /etc/apt/sources.list -} - -setCn(){ - sed -i 's/cdn-fastly.deb.debian.org/mirrors.ustc.edu.cn/'g /etc/apt/sources.list -} - -set163(){ - sed -i 's/cdn-fastly.deb.debian.org/mirrors.163.com/'g /etc/apt/sources.list -} - -setAliyun(){ - sed -i 's/cdn-fastly.deb.debian.org/mirrors.aliyun.com/'g /etc/apt/sources.list -} - -restore(){ - if [ -f /etc/apt/sources.list.bak ]; then - rm /etc/apt/sources.list - mv /etc/apt/sources.list.bak /etc/apt/sources.list - elif [ -f /etc/yum.repos.d/CentOS-Base.repo.bak ]; then - rm /etc/yum.repos.d/CentOS-Base.repo - mv /etc/yum.repos.d/CentOS-Base.repo.bak /etc/yum.repos.d/CentOS-Base.repo - fi -} - -setSources(){ - getAbout - updateInit - case "$release" in - debian) - case $para in - 'fastly'|'-fastly'|'--fastly' ) - setDebian;; - 'cn'|'-cn'|'--cn' ) - setDebian;setCn;; - '163'|'-163'|'--163' ) - setDebian;set163;; - 'aliyun'|'-aliyun'|'--aliyun' ) - setDebian;setAliyun;; - 'aws'|'-aws'|'--aws' ) - setDebian;setAWS;; - 'restore'|'-restore'|'--restore' ) - restore;; - *) - setDebian;; - esac - apt-get update;; - ubuntu) - case $para in - 'restore'|'-restore'|'--restore' ) - restore;; - *) - setUbuntu; - esac - apt-get update;; - centos) - case $para in - 'restore'|'-restore'|'--restore' ) - restore;; - *) - setCentos; - esac - yum makecache;; - esac -} - -para=$1 -setSources -echo -e "${GREEN}Done${PLAIN}" diff --git a/tools.py b/tools.py deleted file mode 100644 index c8ba457..0000000 --- a/tools.py +++ /dev/null @@ -1,70 +0,0 @@ -#!/usr/bin/env python -# -*- coding: UTF-8 -*- - -import time,urllib2,json,sys -import shlex -import datetime -import subprocess - -reload(sys) -sys.setdefaultencoding('utf-8') - -def GetIpipInfo(para): - f = open("ip_json.json",'r') - ijson = json.load(f) - jjson = ijson['location'] - print jjson[para.encode('utf-8')] - -def GetGeoioInfo(para): - ip_api = urllib2.urlopen(r'http://ip-api.com/json') - ijson = json.loads(ip_api.read()) - print ijson[para.encode('utf-8')] - -def GetDiskInfo(para): - temp = ExecShell("df -h -P|grep '/'|grep -v tmpfs")[0]; - temp1 = temp.split('\n'); - diskInfo = []; - n = 0 - cuts = ['/mnt/cdrom','/boot','/boot/efi','/dev','/dev/shm','/run/lock','/run','/run/shm','/run/user']; - for tmp in temp1: - n += 1 - disk = tmp.split(); - if len(disk) < 5: continue; - if disk[1].find('M') != -1: continue; - if disk[1].find('K') != -1: continue; - if len(disk[5].split('/')) > 4: continue; - if disk[5] in cuts: continue; - arr = {} - diskInfo = [disk[1],disk[2],disk[3],disk[4],disk[5]]; - - print(diskInfo[int(para)]); - -def ExecShell(cmdstring, cwd=None, timeout=None, shell=True): - - if shell: - cmdstring_list = cmdstring - else: - cmdstring_list = shlex.split(cmdstring) - if timeout: - end_time = datetime.datetime.now() + datetime.timedelta(seconds=timeout) - - sub = subprocess.Popen(cmdstring_list, cwd=cwd, stdin=subprocess.PIPE,shell=shell,bufsize=4096,stdout=subprocess.PIPE,stderr=subprocess.PIPE) - - while sub.poll() is None: - time.sleep(0.1) - if timeout: - if end_time <= datetime.datetime.now(): - raise Exception("Timeout:%s"%cmdstring) - - return sub.communicate() - -if __name__ == "__main__": - type = sys.argv[1]; - if type == 'disk': - GetDiskInfo(sys.argv[2]) - elif type == 'geoip': - GetGeoioInfo(sys.argv[2]) - elif type == 'ipip': - GetIpipInfo(sys.argv[2]) - else: - print 'ERROR: Parameter error'