├── 1.png ├── 2.png ├── Generate.py ├── README.md ├── ZBench-CN.sh ├── ZBench.sh ├── ZPing-CN.py ├── ZPing.py └── besttrace /1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/FunctionClub/ZBench/fde6a7b932bccfd76124e176d98bec03b28e9160/1.png -------------------------------------------------------------------------------- /2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/FunctionClub/ZBench/fde6a7b932bccfd76124e176d98bec03b28e9160/2.png -------------------------------------------------------------------------------- /Generate.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python 2 | # -*- coding: UTF-8 -*- 3 | 4 | import urllib 5 | import urllib2 6 | 7 | 8 | def change_to_list(filename): 9 | content = open(filename,"r").read().strip() 10 | return list(content.split("\n")) 11 | 12 | 13 | def traceroute_to_dict(filename): 14 | 15 | txtfile = open(filename,"r") 16 | content = txtfile.read().strip().split("\n")[1:] 17 | d=dict() 18 | 19 | for i in range(len(content)): 20 | 21 | line = content[i] 22 | if line[1].isdigit(): 23 | if line[4] != "*" : 24 | ip = line.strip().split(" ")[1] 25 | asn = line.strip().split(" ")[3] 26 | iptest = ip.strip().split(" ")[0] 27 | url = "http://ip-api.com/csv/" + iptest 28 | req = urllib2.Request(url) 29 | res_data = urllib2.urlopen(req) 30 | res = res_data.read() 31 | if res.strip().split(",")[0] == "success" : 32 | isp=res.strip().split(",")[11] 33 | asn=res.strip().split(",")[12] 34 | else: 35 | isp= "*" 36 | latency=line.strip().split(" ")[2] 37 | route = line.strip().split(" ")[4] 38 | step = line[0:2] 39 | else: 40 | latency="*" 41 | asn = "*" 42 | route = "*" 43 | ip = "*" 44 | isp= "*" 45 | step = line[0:2] 46 | 47 | d[int(step)]=dict() 48 | d[int(step)]["ip"]=ip 49 | if int(step) < 3: 50 | d[int(step)]["ip"]="*.*.*.*(已隐藏)" 51 | d[int(step)]["latency"]=latency 52 | d[int(step)]["asn"]=asn 53 | d[int(step)]["route"]=route 54 | d[int(step)]["isp"]=isp 55 | 56 | return dict(d) 57 | 58 | def traceroute_to_table(filename): 59 | d = traceroute_to_dict(filename) 60 | string = "" 61 | for i in sorted(d.keys()): 62 | x = d[i] 63 | template = """ 64 | 65 | {} 66 | {} 67 | {} 68 | {} 69 | {} 70 | {} 71 | 72 | """ 73 | string = string + template.format(i,x["ip"],x["route"],x["isp"],x["asn"],x["latency"]) + "\n" 74 | 75 | writefile = open(filename + "_table","w") 76 | writefile.write(string) 77 | writefile.close() 78 | 79 | 80 | def dict_to_table(d,tab): 81 | 82 | table_class = "ui bottom attached tab segment" 83 | if tab == "first": 84 | table_class = table_class + " active" 85 | 86 | table_html = """ 87 | 88 |
89 | 90 | 91 | 92 | 93 | 94 | 95 | 96 | 97 | 98 | 99 | """.format(table_class,tab) 100 | 101 | for step in sorted(d.keys()): 102 | table_html = table_html + """ 103 | 104 | 105 | 106 | 107 | 108 | 109 | 110 | 111 | 112 | 113 | """.format(step,d[step]["ip"],d[step]["route"],d[step]["isp"],d[step]["asn"],d[step]["latency"]) 114 | table_html = table_html + """ 115 | 116 |
跳数IP路由ISPAS Number延迟
{0}{1}{2}{3}{4}{5}
117 |
118 | """ 119 | return table_html 120 | 121 | html = """ 122 | 123 | 124 | 125 | 126 | 127 | Zbench v1.0 HTML Output 128 | 129 | 130 | 131 | 132 | 133 | 134 | 166 | 167 | 168 |
169 |
170 | 171 |
172 | 您正在使用的是开发中的项目。 173 |
174 |

此程序正处于开发版, 我们无法保证在运行过程中不会出错. 我们将在近期测试后放出正式版,敬请期待.

175 |
176 |
177 | 178 |
179 |
180 |
181 | 测试数据准确性说明 182 |
183 |

请注意,所有的测试数据为测试时的实时数据. 我们不保证您的服务商会在日后一直使用保持完全相同的服务。数据仅供参考.

184 |

185 |
186 |
187 | 188 | 189 |

190 | 191 | 系统信息 192 |

193 | 194 |
195 | 196 | 197 | 198 | 199 | 200 | 201 | 202 | 203 | 206 | 207 | 208 | 209 | 212 | 213 | 214 | 215 | 216 | 219 | 220 | 221 | 222 | 223 | 226 | 227 | 228 | 229 | 230 | 233 | 234 | 235 | 236 | 237 | 240 | 241 | 242 | 243 | 244 | 247 | 248 | 249 | 250 | 251 | 254 | 255 | 256 | 257 | 258 | 261 | 262 | 263 | 264 | 265 | 268 | 269 | 270 | 271 | 272 | 275 | 276 | 277 | 278 | 279 | 282 | 283 | 284 | 285 | 286 |
项目数据
204 | CPU 型号 205 | {0}
210 | CPU 核心数 211 | {1}
217 | CPU 主频 218 | {2}
224 | 硬盘大小 225 | {3}
231 | 内存大小 232 | {4}
238 | SWAP 交换空间大小 239 | {5}
245 | 在线时长 246 | {6}
252 | 系统负载 253 | {7}
259 | 系统 260 | {8}
266 | 架构 267 | {9}
273 | 核心 274 | {10}
280 | 虚拟化技术 281 | {11}
287 |
288 | 289 | 290 | 291 | 292 | 293 |

294 | 295 | 硬盘 I/O 296 |

297 | 298 |
299 | 300 | 301 | 302 | 303 | 304 | 305 | 306 | 307 | 310 | 311 | 312 | 313 | 316 | 317 | 318 | 319 | 322 | 323 | 324 | 325 | 326 |
次数速度
308 | 第一次测试 309 | {12}
314 | 第二次测试 315 | {13}
320 | 第三次测试 321 | {14}
327 |
328 | 329 | 330 | 331 | 332 | 333 | 334 | 335 |

336 | 337 | 网络测试 338 |

339 | 340 |
341 | 342 | 343 | 344 | 345 | 346 | 347 | 348 | 349 | 350 | 351 | 352 | 353 | 354 | 355 | 356 | 357 | 358 | 359 | 360 | 361 | 362 | 363 | 364 | 365 | 366 | 367 | 368 | 369 | 370 | 371 | 372 | 373 | 374 | 375 | 376 | 377 | 378 | 379 | 380 | 381 | 382 | 383 | 384 | 385 | 386 | 387 | 388 | 389 | 390 | 391 | 392 | 393 | 394 | 395 | 396 | 397 | 398 | 399 | 400 | 401 | 402 | 403 | 404 | 405 | 406 | 407 | 408 | 409 | 410 | 411 | 412 | 413 | 414 | 415 | 416 | 417 |
节点IP 地址下载速度延迟
CacheFly{15}{16}{17}
Linode 日本{18}{19}{20}
Linode 新加坡{21}{22}{23}
Linode 英国{24}{25}{26}
Linode 法兰克福{27}{28}{29}
Linode 加拿大{30}{31}{32}
Softlayer 达拉斯{33}{34}{35}
Softlayer 西雅图{36}{37}{38}
Softlayer 法兰克福{39}{40}{41}
Softlayer 新加坡{42}{43}{44}
Softlayer 香港{45}{46}{47}
418 | 419 | 420 | 421 |
422 | 423 | 424 | 425 | 426 | 427 | 428 | 429 | 430 | 431 | 432 | 433 | 434 | 435 | 436 | 437 | 438 | 439 | 440 | 441 | 442 | 443 | 444 | 445 | 446 | 447 | 448 | 449 | 450 | 451 | 452 | 453 | 454 | 455 | 456 | 457 | 458 | 459 | 460 | 461 | 462 | 463 | 464 | 465 | 466 | 467 | 468 | 469 | 470 | 471 | 472 | 473 | 474 | 475 | 476 | 477 | 478 | 479 | 480 | 481 |
节点上传速度下载速度延迟
上海电信{48}{49}{50}
成都电信{51}{52}{53}
西安电信{54}{55}{56}
上海联通{57}{58}{59}
重庆联通{60}{61}{62}
北京电信{63}{64}{65}
北京联通{66}{67}{68}
湖南电信{69}{70}{71}
482 |
483 | 484 | 485 |

486 | 487 | 路由追踪 488 |

489 | 490 | 491 |
492 | 501 | 502 | """ 503 | 504 | 505 | footer = """ 506 |
507 |
508 | 509 |
510 |

CopyRight 2016-2018 Function Club. All Right Reserved. Published By 主机博客

511 |
512 | 513 | 514 | 613 | 614 | 615 | 616 | """ 617 | 618 | info = change_to_list("/tmp/info.txt") 619 | 620 | speed = change_to_list("/tmp/speed.txt") 621 | 622 | speed_cn = change_to_list("/tmp/speed_cn.txt") 623 | 624 | shm = traceroute_to_dict("/tmp/shm.txt") 625 | traceroute_to_table("/tmp/shm.txt") 626 | shm_html = dict_to_table(shm,"first") 627 | 628 | sht = traceroute_to_dict("/tmp/sht.txt") 629 | traceroute_to_table("/tmp/sht.txt") 630 | sht_html = dict_to_table(sht,"second") 631 | 632 | shu = traceroute_to_dict("/tmp/shu.txt") 633 | traceroute_to_table("/tmp/shu.txt") 634 | shu_html = dict_to_table(shu,"third") 635 | 636 | gdm = traceroute_to_dict("/tmp/gdm.txt") 637 | traceroute_to_table("/tmp/gdm.txt") 638 | gdm_html = dict_to_table(gdm,"fourth") 639 | 640 | gdt = traceroute_to_dict("/tmp/gdt.txt") 641 | traceroute_to_table("/tmp/gdt.txt") 642 | gdt_html = dict_to_table(gdt,"fifth") 643 | 644 | gdu = traceroute_to_dict("/tmp/gdu.txt") 645 | traceroute_to_table("/tmp/gdu.txt") 646 | gdu_html = dict_to_table(gdu,"sixth") 647 | 648 | own = traceroute_to_dict("/tmp/own.txt") 649 | traceroute_to_table("/tmp/own.txt") 650 | own_html = dict_to_table(own,"seventh") 651 | 652 | html = html.format(info[0],info[1],info[2],info[3],info[4],info[5],info[6],info[7],info[8],info[9],info[10],info[11],info[12],info[13],info[14], \ 653 | 654 | speed[0],speed[1],speed[2],speed[3],speed[4],speed[5],speed[6],speed[7],speed[8],speed[9],speed[10],speed[11],speed[12],speed[13],speed[14],speed[15],\ 655 | 656 | speed[16],speed[17],speed[18],speed[19],speed[20],speed[21],speed[22],speed[23],speed[24],speed[25],speed[26],speed[27],speed[28],speed[29],speed[30],speed[31],speed[32],\ 657 | 658 | speed_cn[0],speed_cn[1],speed_cn[2],speed_cn[3],speed_cn[4],speed_cn[5],speed_cn[6],speed_cn[7],speed_cn[8],speed_cn[9],speed_cn[10],speed_cn[11],speed_cn[12],\ 659 | 660 | speed_cn[13],speed_cn[14],speed_cn[15],speed_cn[16],speed_cn[17],\ 661 | 662 | speed_cn[18],speed_cn[19],speed_cn[20],speed_cn[21],speed_cn[22],speed_cn[23]) 663 | 664 | html = html + shm_html + sht_html + shu_html + gdm_html + gdt_html + gdu_html + own_html + footer 665 | 666 | web = open("/root/report.html","w") 667 | 668 | web.write(html) 669 | 670 | web.close() 671 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Zench 2 | 3 | 又一个Linux VPS测评脚本 4 | 5 | ## 说明 6 | 7 | 平时测试VPS的时候一直是靠着 **Bench.sh** 来测试的,最近看到 **Oldking**大佬 的 **SuperBench** 也很方便。我自己把这两者的脚本结合在一起,然后加入 **Ping** 以及 **路由测试** 功能。比较懒人,简单快捷。方便VPS测评站的朋友们使用。因为会生成测评报告,可以很方便地分享给其他朋友看自己的测评数据。 8 | 9 | 示例(Demo):[https://www.zhujiboke.com/zbench-example.html](https://www.zhujiboke.com/zbench-example.html) 10 | 11 | ## 脚本命令 12 | 13 | 如果中文版出现乱码等情况,请换成英文版。 14 | 15 | 中文版: 16 | 17 | wget -N --no-check-certificate https://raw.githubusercontent.com/FunctionClub/ZBench/master/ZBench-CN.sh && bash ZBench-CN.sh 18 | 19 | 英文版: 20 | 21 | wget -N --no-check-certificate https://raw.githubusercontent.com/FunctionClub/ZBench/master/ZBench.sh && bash ZBench.sh 22 | 23 | ## 效果图 24 | 25 | ![1.png](1.png) 26 | 27 | 28 | ![2.png](2.png) 29 | 30 | ## 引用 31 | 32 | * Bench.sh ( [https://teddysun.com/444.html](https://teddysun.com/444.html) ) 33 | * SuperBench ( [https://www.oldking.net/350.html](https://www.oldking.net/350.html) ) 34 | * python实现ping程序 ( [https://www.s0nnet.com/archives/python-icmp](https://www.s0nnet.com/archives/python-icmp) ) 35 | * Python 设置颜色 ( [http://www.pythoner.com/357.html](http://www.pythoner.com/357.html) ) 36 | * Kirito's Blog ( [https://www.ixh.me](https://www.ixh.me) ) 37 | 38 | 39 | -------------------------------------------------------------------------------- /ZBench-CN.sh: -------------------------------------------------------------------------------- 1 | # Check if user is root 2 | [ $(id -u) != "0" ] && { echo "${CFAILURE}Error: You must be root to run this script${CEND}"; exit 1; } 3 | 4 | # Check if wget installed 5 | if [ ! -e '/usr/bin/wget' ]; then 6 | echo "Error: wget command not found. You must be install wget command at first." 7 | exit 1 8 | fi 9 | read -p "请输入你的服务器提供商: " Provider 10 | 11 | 12 | # Get IP 13 | OwnerIP=$(who am i | awk '{print $NF}' | sed -e 's/[()]//g') 14 | while :; do echo 15 | read -p "请确认你所在地的IP:${OwnerIP} [y/n]: " ifOwnerIP 16 | if [[ ! ${ifOwnerIP} =~ ^[y,n]$ ]]; then 17 | echo "输入错误! 请确保你输入的是 'y' 或者 'n'" 18 | else 19 | break 20 | fi 21 | done 22 | if [[ ${ifOwnerIP} == "n" ]]; then 23 | while :; do echo 24 | read -p "请输入你所在地的IP: " OwnerIP 25 | if [[ ! ${OwnerIP} ]]; then 26 | echo "输入错误!IP地址不能为空!" 27 | else 28 | break 29 | fi 30 | done 31 | fi 32 | 33 | 34 | # Check release 35 | if [ -f /etc/redhat-release ]; then 36 | release="centos" 37 | elif cat /etc/issue | grep -Eqi "debian"; then 38 | release="debian" 39 | elif cat /etc/issue | grep -Eqi "ubuntu"; then 40 | release="ubuntu" 41 | elif cat /etc/issue | grep -Eqi "centos|red hat|redhat"; then 42 | release="centos" 43 | elif cat /proc/version | grep -Eqi "debian"; then 44 | release="debian" 45 | elif cat /proc/version | grep -Eqi "ubuntu"; then 46 | release="ubuntu" 47 | elif cat /proc/version | grep -Eqi "centos|red hat|redhat"; then 48 | release="centos" 49 | fi 50 | 51 | 52 | # Colors 53 | RED='\033[0;31m' 54 | GREEN='\033[0;32m' 55 | YELLOW='\033[0;33m' 56 | SKYBLUE='\033[0;36m' 57 | PLAIN='\033[0m' 58 | 59 | rm -rf /tmp/report && mkdir /tmp/report 60 | 61 | echo "正在安装必要的依赖,请耐心等待..." 62 | 63 | 64 | 65 | # Install Virt-what 66 | if [ ! -e '/usr/sbin/virt-what' ]; then 67 | echo "Installing Virt-What......" 68 | if [ "${release}" == "centos" ]; then 69 | yum -y install virt-what > /dev/null 2>&1 70 | else 71 | apt-get update 72 | apt-get -y install virt-what > /dev/null 2>&1 73 | fi 74 | fi 75 | 76 | # Install uuid 77 | echo "Installing uuid......" 78 | if [ "${release}" == "centos" ]; then 79 | yum -y install uuid > /dev/null 2>&1 80 | else 81 | apt-get -y install uuid > /dev/null 2>&1 82 | fi 83 | 84 | 85 | # Install curl 86 | echo "Installing curl......" 87 | if [ "${release}" == "centos" ]; then 88 | yum -y install curl > /dev/null 2>&1 89 | else 90 | apt-get -y install curl > /dev/null 2>&1 91 | fi 92 | 93 | 94 | # Install Besttrace 95 | if [ ! -e '/tmp/besttrace' ]; then 96 | echo "Installing Besttrace......" 97 | dir=$(pwd) 98 | cd /tmp/ 99 | wget -N --no-check-certificate https://raw.githubusercontent.com/FunctionClub/ZBench/master/besttrace > /dev/null 2>&1 100 | cd $dir 101 | fi 102 | chmod a+rx /tmp/besttrace 103 | 104 | # Check Python 105 | if [ ! -e '/usr/bin/python' ]; then 106 | echo "Installing Python......" 107 | if [ "${release}" == "centos" ]; then 108 | yum update > /dev/null 2>&1 109 | yum -y install python 110 | else 111 | apt-get update > /dev/null 2>&1 112 | apt-get -y install python 113 | fi 114 | fi 115 | 116 | # Install Speedtest 117 | if [ ! -e '/tmp/speedtest.py' ]; then 118 | echo "Installing SpeedTest......" 119 | dir=$(pwd) 120 | cd /tmp/ 121 | wget -N --no-check-certificate https://raw.github.com/sivel/speedtest-cli/master/speedtest.py > /dev/null 2>&1 122 | cd $dir 123 | fi 124 | chmod a+rx /tmp/speedtest.py 125 | 126 | 127 | # Install Zping-CN 128 | if [ ! -e '/tmp/ZPing-CN.py' ]; then 129 | echo "Installing ZPing-CN.py......" 130 | dir=$(pwd) 131 | cd /tmp/ 132 | wget -N --no-check-certificate https://raw.githubusercontent.com/FunctionClub/ZBench/master/ZPing-CN.py > /dev/null 2>&1 133 | cd $dir 134 | fi 135 | chmod a+rx /tmp/ZPing-CN.py 136 | 137 | #"TraceRoute to Shanghai Telecom" 138 | /tmp/besttrace 61.129.42.6 > /tmp/sht.txt 2>&1 & 139 | #"TraceRoute to Shanghai Mobile" 140 | /tmp/besttrace speedtest2.sh.chinamobile.com > /tmp/shm.txt 2>&1 & 141 | #"TraceRoute to Shanghai Unicom" 142 | /tmp/besttrace 210.22.80.1 > /tmp/shu.txt 2>&1 & 143 | #"TraceRoute to Guangdong Telecom" 144 | /tmp/besttrace 121.14.220.240 > /tmp/gdt.txt 2>&1 & 145 | #"TraceRoute to Guangdong Mobile" 146 | /tmp/besttrace 211.136.192.6 > /tmp/gdm.txt 2>&1 & 147 | #"TraceRoute to Guangdong Unicom" 148 | /tmp/besttrace 221.5.88.88 > /tmp/gdu.txt 2>&1 & 149 | #"TraceRoute to Owner's Network" 150 | /tmp/besttrace ${OwnerIP} > /tmp/own.txt 2>&1 & 151 | 152 | 153 | 154 | 155 | get_opsy() { 156 | [ -f /etc/redhat-release ] && awk '{print ($1,$3~/^[0-9]/?$3:$4)}' /etc/redhat-release && return 157 | [ -f /etc/os-release ] && awk -F'[= "]' '/PRETTY_NAME/{print $3,$4,$5}' /etc/os-release && return 158 | [ -f /etc/lsb-release ] && awk -F'[="]+' '/DESCRIPTION/{print $2}' /etc/lsb-release && return 159 | } 160 | 161 | next() { 162 | printf "%-74s\n" "-" | sed 's/\s/-/g' 163 | } 164 | 165 | speed_test() { 166 | local speedtest=$(wget -4O /dev/null -T300 $1 2>&1 | awk '/\/dev\/null/ {speed=$3 $4} END {gsub(/\(|\)/,"",speed); print speed}') 167 | local ipaddress=$(ping -c1 -n `awk -F'/' '{print $3}' <<< $1` | awk -F'[()]' '{print $2;exit}') 168 | local nodeName=$2 169 | local latency=$(ping $ipaddress -c 3 | grep avg | awk -F / '{print $5}')" ms" 170 | printf "${YELLOW}%-26s${GREEN}%-18s${RED}%-20s${SKYBLUE}%-12s${PLAIN}\n" "${nodeName}" "${ipaddress}" "${speedtest}" "${latency}" 171 | 172 | #Record Speed Data 173 | echo ${ipaddress} >> /tmp/speed.txt 174 | echo ${speedtest} >> /tmp/speed.txt 175 | echo ${latency} >> /tmp/speed.txt 176 | } 177 | 178 | speed() { 179 | speed_test 'http://cachefly.cachefly.net/100mb.test' 'CacheFly' 180 | speed_test 'http://speedtest.tokyo.linode.com/100MB-tokyo.bin' 'Linode, Tokyo, JP' 181 | speed_test 'http://speedtest.singapore.linode.com/100MB-singapore.bin' 'Linode, Singapore, SG' 182 | speed_test 'http://speedtest.london.linode.com/100MB-london.bin' 'Linode, London, UK' 183 | speed_test 'http://speedtest.frankfurt.linode.com/100MB-frankfurt.bin' 'Linode, Frankfurt, DE' 184 | speed_test 'http://speedtest.fremont.linode.com/100MB-fremont.bin' 'Linode, Fremont, CA' 185 | speed_test 'http://speedtest.dal05.softlayer.com/downloads/test100.zip' 'Softlayer, Dallas, TX' 186 | speed_test 'http://speedtest.sea01.softlayer.com/downloads/test100.zip' 'Softlayer, Seattle, WA' 187 | speed_test 'http://speedtest.fra02.softlayer.com/downloads/test100.zip' 'Softlayer, Frankfurt, DE' 188 | speed_test 'http://speedtest.sng01.softlayer.com/downloads/test100.zip' 'Softlayer, Singapore, SG' 189 | speed_test 'http://speedtest.hkg02.softlayer.com/downloads/test100.zip' 'Softlayer, HongKong, CN' 190 | } 191 | 192 | speed_test_cn(){ 193 | if [[ $1 == '' ]]; then 194 | temp=$(python /tmp/speedtest.py --share 2>&1) 195 | is_down=$(echo "$temp" | grep 'Download') 196 | if [[ ${is_down} ]]; then 197 | local REDownload=$(echo "$temp" | awk -F ':' '/Download/{print $2}') 198 | local reupload=$(echo "$temp" | awk -F ':' '/Upload/{print $2}') 199 | local relatency=$(echo "$temp" | awk -F ':' '/Hosted/{print $2}') 200 | local nodeName=$2 201 | 202 | printf "${YELLOW}%-29s${GREEN}%-18s${RED}%-20s${SKYBLUE}%-12s${PLAIN}\n" "${nodeName}" "${reupload}" "${REDownload}" "${relatency}" 203 | else 204 | local cerror="ERROR" 205 | fi 206 | else 207 | temp=$(python /tmp/speedtest.py --server $1 --share 2>&1) 208 | is_down=$(echo "$temp" | grep 'Download') 209 | if [[ ${is_down} ]]; then 210 | local REDownload=$(echo "$temp" | awk -F ':' '/Download/{print $2}') 211 | local reupload=$(echo "$temp" | awk -F ':' '/Upload/{print $2}') 212 | local relatency=$(echo "$temp" | awk -F ':' '/Hosted/{print $2}') 213 | temp=$(echo "$relatency" | awk -F '.' '{print $1}') 214 | if [[ ${temp} -gt 1000 ]]; then 215 | relatency=" 000.000 ms" 216 | fi 217 | local nodeName=$2 218 | 219 | printf "${YELLOW}%-29s${GREEN}%-18s${RED}%-20s${SKYBLUE}%-12s${PLAIN}\n" "${nodeName}" "${reupload}" "${REDownload}" "${relatency}" 220 | else 221 | local cerror="ERROR" 222 | fi 223 | fi 224 | 225 | #Record Speed_cn Data 226 | echo ${reupload} >> /tmp/speed_cn.txt 227 | echo ${REDownload} >> /tmp/speed_cn.txt 228 | echo ${relatency} >> /tmp/speed_cn.txt 229 | } 230 | 231 | speed_cn() { 232 | 233 | speed_test_cn '12637' '襄阳电信' 234 | speed_test_cn '3633' '上海电信' 235 | speed_test_cn '4624' '成都电信' 236 | speed_test_cn '4863' "西安电信" 237 | speed_test_cn '5083' '上海联通' 238 | speed_test_cn '5726' '重庆联通' 239 | speed_test_cn '4751' "北京电信" 240 | speed_test_cn '5145' '北京联通' 241 | speed_test_cn '6132' '湖南电信' 242 | 243 | rm -rf /tmp/speedtest.py 244 | } 245 | 246 | 247 | io_test() { 248 | (LANG=C dd if=/dev/zero of=test_$$ bs=64k count=16k conv=fdatasync && rm -f test_$$ ) 2>&1 | awk -F, '{io=$NF} END { print io}' | sed 's/^[ \t]*//;s/[ \t]*$//' 249 | } 250 | 251 | calc_disk() { 252 | local total_size=0 253 | local array=$@ 254 | for size in ${array[@]} 255 | do 256 | [ "${size}" == "0" ] && size_t=0 || size_t=`echo ${size:0:${#size}-1}` 257 | [ "`echo ${size:(-1)}`" == "K" ] && size=0 258 | [ "`echo ${size:(-1)}`" == "M" ] && size=$( awk 'BEGIN{printf "%.1f", '$size_t' / 1024}' ) 259 | [ "`echo ${size:(-1)}`" == "T" ] && size=$( awk 'BEGIN{printf "%.1f", '$size_t' * 1024}' ) 260 | [ "`echo ${size:(-1)}`" == "G" ] && size=${size_t} 261 | total_size=$( awk 'BEGIN{printf "%.1f", '$total_size' + '$size'}' ) 262 | done 263 | echo ${total_size} 264 | } 265 | 266 | cname=$( awk -F: '/model name/ {name=$2} END {print name}' /proc/cpuinfo | sed 's/^[ \t]*//;s/[ \t]*$//' ) 267 | cores=$( awk -F: '/model name/ {core++} END {print core}' /proc/cpuinfo ) 268 | freq=$( awk -F: '/cpu MHz/ {freq=$2} END {print freq}' /proc/cpuinfo | sed 's/^[ \t]*//;s/[ \t]*$//' ) 269 | tram=$( free -m | awk '/Mem/ {print $2}' ) 270 | uram=$( free -m | awk '/Mem/ {print $3}' ) 271 | swap=$( free -m | awk '/Swap/ {print $2}' ) 272 | uswap=$( free -m | awk '/Swap/ {print $3}' ) 273 | 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 ) 274 | load=$( w | head -1 | awk -F'load average:' '{print $2}' | sed 's/^[ \t]*//;s/[ \t]*$//' ) 275 | opsy=$( get_opsy ) 276 | arch=$( uname -m ) 277 | lbit=$( getconf LONG_BIT ) 278 | kern=$( uname -r ) 279 | ipv6=$( wget -qO- -t1 -T2 ipv6.icanhazip.com ) 280 | disk_size1=($( LANG=C df -hPl | grep -wvE '\-|none|tmpfs|devtmpfs|by-uuid|chroot|Filesystem' | awk '{print $2}' )) 281 | disk_size2=($( LANG=C df -hPl | grep -wvE '\-|none|tmpfs|devtmpfs|by-uuid|chroot|Filesystem' | awk '{print $3}' )) 282 | disk_total_size=$( calc_disk ${disk_size1[@]} ) 283 | disk_used_size=$( calc_disk ${disk_size2[@]} ) 284 | 285 | 286 | clear 287 | next 288 | echo -e "CPU 型号 : ${SKYBLUE}$cname${PLAIN}" 289 | echo -e "CPU 核心数 : ${SKYBLUE}$cores${PLAIN}" 290 | echo -e "CPU 频率 : ${SKYBLUE}$freq MHz${PLAIN}" 291 | echo -e "总硬盘大小 : ${SKYBLUE}$disk_total_size GB ($disk_used_size GB Used)${PLAIN}" 292 | echo -e "总内存大小 : ${SKYBLUE}$tram MB ($uram MB Used)${PLAIN}" 293 | echo -e "SWAP大小 : ${SKYBLUE}$swap MB ($uswap MB Used)${PLAIN}" 294 | echo -e "开机时长 : ${SKYBLUE}$up${PLAIN}" 295 | echo -e "系统负载 : ${SKYBLUE}$load${PLAIN}" 296 | echo -e "系统 : ${SKYBLUE}$opsy${PLAIN}" 297 | echo -e "架构 : ${SKYBLUE}$arch ($lbit Bit)${PLAIN}" 298 | echo -e "内核 : ${SKYBLUE}$kern${PLAIN}" 299 | echo -ne "虚拟化平台 : " 300 | virtua=$(virt-what) 2>/dev/null 301 | 302 | if [[ ${virtua} ]]; then 303 | echo -e "${SKYBLUE}$virtua${PLAIN}" 304 | else 305 | echo -e "${SKYBLUE}No Virt${PLAIN}" 306 | fi 307 | 308 | 309 | next 310 | io1=$( io_test ) 311 | echo -e "硬盘I/O (第一次测试) : ${YELLOW}$io1${PLAIN}" 312 | io2=$( io_test ) 313 | echo -e "硬盘I/O (第二次测试) : ${YELLOW}$io2${PLAIN}" 314 | io3=$( io_test ) 315 | echo -e "硬盘I/O (第三次测试) : ${YELLOW}$io3${PLAIN}" 316 | next 317 | 318 | ##Record All Test data 319 | rm -rf /tmp/info.txt 320 | touch /tmp/info.txt 321 | echo $cname >> /tmp/info.txt 322 | echo $cores >> /tmp/info.txt 323 | echo $freq MHz >> /tmp/info.txt 324 | echo "$disk_total_size GB ($disk_used_size GB 已使用) ">> /tmp/info.txt 325 | echo "$tram MB ($uram MB 已使用) ">> /tmp/info.txt 326 | echo "$swap MB ($uswap MB 已使用)" >> /tmp/info.txt 327 | echo $up >> /tmp/info.txt 328 | echo $load >> /tmp/info.txt 329 | echo $opsy >> /tmp/info.txt 330 | echo "$arch ($lbit 位) ">> /tmp/info.txt 331 | echo $kern >> /tmp/info.txt 332 | echo $virtua >> /tmp/info.txt 333 | echo $io1 >> /tmp/info.txt 334 | echo $io2 >> /tmp/info.txt 335 | echo $io3 >> /tmp/info.txt 336 | AKEY=$( uuid ) 337 | 338 | printf "%-30s%-20s%-24s%-12s\n" "节点名称" "IP地址" "下载速度" "延迟" 339 | speed && next 340 | printf "%-30s%-22s%-24s%-12s\n" "节点名称" "上传速度" "下载速度" "延迟" 341 | speed_cn && next 342 | python /tmp/ZPing-CN.py 343 | next 344 | 345 | NetCFspeec=$( sed -n "2p" /tmp/speed.txt ) 346 | NetCFping=$( sed -n "3p" /tmp/speed.txt ) 347 | NetLJPspeed=$( sed -n "5p" /tmp/speed.txt ) 348 | NetLJPping=$( sed -n "6p" /tmp/speed.txt ) 349 | NetLSGspeed=$( sed -n "8p" /tmp/speed.txt ) 350 | NetLSGping=$( sed -n "9p" /tmp/speed.txt ) 351 | NetLUKspeed=$( sed -n "11p" /tmp/speed.txt ) 352 | NetLUKping=$( sed -n "12p" /tmp/speed.txt ) 353 | NetLDEspeed=$( sed -n "14p" /tmp/speed.txt ) 354 | NetLDEping=$( sed -n "15p" /tmp/speed.txt ) 355 | NetLCAspeed=$( sed -n "17p" /tmp/speed.txt ) 356 | NetLCAping=$( sed -n "18p" /tmp/speed.txt ) 357 | NetSTXspeed=$( sed -n "20p" /tmp/speed.txt ) 358 | NetSTXping=$( sed -n "21p" /tmp/speed.txt ) 359 | NetSWAspeed=$( sed -n "23p" /tmp/speed.txt ) 360 | NetSWAping=$( sed -n "24p" /tmp/speed.txt ) 361 | NetSDEspeed=$( sed -n "26p" /tmp/speed.txt ) 362 | NetSDEping=$( sed -n "27p" /tmp/speed.txt ) 363 | NetSSGspeed=$( sed -n "29p" /tmp/speed.txt ) 364 | NetSSGping=$( sed -n "30p" /tmp/speed.txt ) 365 | NetSCNspeed=$( sed -n "32p" /tmp/speed.txt ) 366 | NetSCNping=$( sed -n "33p" /tmp/speed.txt ) 367 | 368 | 369 | NetUPST=$( sed -n "4p" /tmp/speed_cn.txt ) 370 | NetDWST=$( sed -n "5p" /tmp/speed_cn.txt ) 371 | NetPiST=$( sed -n "6p" /tmp/speed_cn.txt ) 372 | NetUPCT=$( sed -n "7p" /tmp/speed_cn.txt ) 373 | NetDWCT=$( sed -n "8p" /tmp/speed_cn.txt ) 374 | NetPiCT=$( sed -n "9p" /tmp/speed_cn.txt ) 375 | NetUPXT=$( sed -n "10p" /tmp/speed_cn.txt ) 376 | NetDWXT=$( sed -n "11p" /tmp/speed_cn.txt ) 377 | NetPiXT=$( sed -n "12p" /tmp/speed_cn.txt ) 378 | NetUPSU=$( sed -n "13p" /tmp/speed_cn.txt ) 379 | NetDWSU=$( sed -n "14p" /tmp/speed_cn.txt ) 380 | NetPiSU=$( sed -n "15p" /tmp/speed_cn.txt ) 381 | NetUPCU=$( sed -n "16p" /tmp/speed_cn.txt ) 382 | NetDWCU=$( sed -n "17p" /tmp/speed_cn.txt ) 383 | NetPiCU=$( sed -n "18p" /tmp/speed_cn.txt ) 384 | NetUPXM=$( sed -n "19p" /tmp/speed_cn.txt ) 385 | NetDWXM=$( sed -n "20p" /tmp/speed_cn.txt ) 386 | NetPiXM=$( sed -n "21p" /tmp/speed_cn.txt ) 387 | NetUPSM=$( sed -n "22p" /tmp/speed_cn.txt ) 388 | NetDWSM=$( sed -n "23p" /tmp/speed_cn.txt ) 389 | NetPiSM=$( sed -n "24p" /tmp/speed_cn.txt ) 390 | NetUPCM=$( sed -n "25p" /tmp/speed_cn.txt ) 391 | NetDWCM=$( sed -n "26p" /tmp/speed_cn.txt ) 392 | NetPiCM=$( sed -n "27p" /tmp/speed_cn.txt ) 393 | 394 | 395 | wget -N --no-check-certificate https://raw.githubusercontent.com/FunctionClub/ZBench/master/Generate.py >> /dev/null 2>&1 396 | python Generate.py && rm -rf Generate.py && cp /root/report.html /tmp/report/index.html 397 | TSM=$( cat /tmp/shm.txt_table ) 398 | TST=$( cat /tmp/sht.txt_table ) 399 | TSU=$( cat /tmp/shu.txt_table ) 400 | TGM=$( cat /tmp/gdm.txt_table ) 401 | TGT=$( cat /tmp/gdt.txt_table ) 402 | TGU=$( cat /tmp/gdu.txt_table ) 403 | curl 'http://api.zbench.kirito.moe/action.php' --data "CPUmodel=$cname &CPUspeed=$freq MHz &CPUcore=$cores &HDDsize=$disk_total_size GB ($disk_used_size GB 已使用) &RAMsize=$tram MB ($uram MB 已使用)&SWAPsize=$swap MB ($uswap MB 已使用)&UPtime= $up&Arch=1&systemload=$load&OS= $opsy &Arch=$arch ($lbit 位)&Kernel=$kern &Virmethod=$virtua &IOa=$io1&IOb=$io2&IOc=$io3&NetCFspeec=$NetCFspeec&NetCFping=$NetCFping&NetLJPspeed=$NetLJPspeed&NetLJPping=$NetLJPping&NetLSGspeed=$NetLSGspeed&NetLSGping=$NetLSGping&NetLUKspeed=$NetLUKspeed&NetLUKping=$NetLUKping&NetLDEspeed=$NetLDEspeed&NetLDEping=$NetLDEping&NetLCAspeed=$NetLCAspeed&NetLCAping=$NetLCAping&NetSTXspeed=$NetSTXspeed&NetSTXping=$NetSTXping&NetSWAspeed=$NetSWAspeed&NetSWAping=$NetSWAping&NetSDEspeed=$NetSDEspeed&NetSDEping=$NetSDEping&NetSSGspeed=$NetSSGspeed&NetSSGping=$NetSSGping&NetSCNspeed=$NetSCNspeed&NetSCNping=$NetSCNping&NetUPST=$NetUPST&NetDWST=$NetDWST&NetPiST=$NetPiST&NetUPCT=$NetUPCT&NetDWCT=$NetDWCT&NetPiCT=$NetPiCT&NetUPXT=$NetUPXT&NetDWXT=$NetDWXT&NetPiXT=$NetPiXT&NetUPSU=$NetUPSU&NetDWSU=$NetDWSU&NetPiSU=$NetPiSU&NetUPCU=$NetUPCU&NetDWCU=$NetDWCU&NetPiCU=$NetPiCU&NetUPXM=$NetUPXM&NetDWXM=$NetDWXM&NetPiXM=$NetPiXM&NetUPSM=$NetUPSM&NetDWSM=$NetDWSM&NetPiSM=$NetPiSM&NetUPCM=$NetUPCM&NetDWCM=$NetDWCM&NetPiCM=$NetPiCM&TSM=$TSM&TST=$TST&TSU=$TSU&TGM=$TGM&TGT=$TGT&TGU=$TGU&AKEY=$AKEY&Provider=$Provider" 404 | IKEY=$(curl "http://api.zbench.kirito.moe/getkey.php?AKEY=$AKEY" 2>/dev/null) 405 | echo "在线查看测评报告:https://zbench.kirito.moe/record-cn.php?IKEY=$IKEY" 406 | echo "您的测评报告已保存在 /root/report.html" 407 | 408 | # If use simple http server 409 | while :; do echo 410 | read -p "你想现在查看您的测评报告吗? [y/n]: " ifreport 411 | if [[ ! $ifreport =~ ^[y,n]$ ]]; then 412 | echo "输入错误! 请确保你输入的是 'y' 或者 'n'" 413 | else 414 | break 415 | fi 416 | done 417 | 418 | if [[ $ifreport == 'y' ]];then 419 | echo "" 420 | myip=`curl -m 10 -s http://members.3322.org/dyndns/getip` 421 | echo "访问 http://${myip}:8001/index.html 查看您的测试报告,按 Ctrl + C 退出" 422 | cd /tmp/report 423 | python -m SimpleHTTPServer 8001 424 | iptables -I INPUT -m state --state NEW -m tcp -p tcp --dport 8001 -j ACCEPT 425 | fi 426 | -------------------------------------------------------------------------------- /ZBench.sh: -------------------------------------------------------------------------------- 1 | # Check if user is root 2 | [ $(id -u) != "0" ] && { echo "${CFAILURE}Error: You must be root to run this script${CEND}"; exit 1; } 3 | 4 | # Check if wget installed 5 | if [ ! -e '/usr/bin/wget' ]; then 6 | echo "Error: wget command not found. You must be install wget command at first." 7 | exit 1 8 | fi 9 | read -p "Please Enter Your Host Provider: " Provider 10 | 11 | 12 | # Get IP 13 | OwnerIP=$(who am i | awk '{print $NF}' | sed -e 's/[()]//g') 14 | while :; do echo 15 | read -p "Please Confirm Your Client IP:${OwnerIP} [y/n]: " ifOwnerIP 16 | if [[ ! ${ifOwnerIP} =~ ^[y,n]$ ]]; then 17 | echo "Input error! Please only input 'y' or 'n'" 18 | else 19 | break 20 | fi 21 | done 22 | if [[ ${ifOwnerIP} == "n" ]]; then 23 | while :; do echo 24 | read -p "Please Enter Your Client IP: " OwnerIP 25 | if [[ ! ${OwnerIP} ]]; then 26 | echo "Input error! Cannot be void!" 27 | else 28 | break 29 | fi 30 | done 31 | fi 32 | 33 | 34 | # Check release 35 | if [ -f /etc/redhat-release ]; then 36 | release="centos" 37 | elif cat /etc/issue | grep -Eqi "debian"; then 38 | release="debian" 39 | elif cat /etc/issue | grep -Eqi "ubuntu"; then 40 | release="ubuntu" 41 | elif cat /etc/issue | grep -Eqi "centos|red hat|redhat"; then 42 | release="centos" 43 | elif cat /proc/version | grep -Eqi "debian"; then 44 | release="debian" 45 | elif cat /proc/version | grep -Eqi "ubuntu"; then 46 | release="ubuntu" 47 | elif cat /proc/version | grep -Eqi "centos|red hat|redhat"; then 48 | release="centos" 49 | fi 50 | 51 | 52 | # Colors 53 | RED='\033[0;31m' 54 | GREEN='\033[0;32m' 55 | YELLOW='\033[0;33m' 56 | SKYBLUE='\033[0;36m' 57 | PLAIN='\033[0m' 58 | 59 | rm -rf /tmp/report && mkdir /tmp/report 60 | 61 | echo "Installing required packages, please wait..." 62 | 63 | # Install Virt-what 64 | if [ ! -e '/usr/sbin/virt-what' ]; then 65 | echo "Installing Virt-What......" 66 | if [ "${release}" == "centos" ]; then 67 | yum -y install virt-what > /dev/null 2>&1 68 | else 69 | apt-get update > /dev/null 2>&1 70 | apt-get -y install virt-what > /dev/null 2>&1 71 | fi 72 | fi 73 | 74 | 75 | 76 | # Install uuid 77 | echo "Installing uuid......" 78 | if [ "${release}" == "centos" ]; then 79 | yum -y install uuid > /dev/null 2>&1 80 | else 81 | apt-get -y install uuid > /dev/null 2>&1 82 | fi 83 | 84 | 85 | # Install curl 86 | echo "Installing curl......" 87 | if [ "${release}" == "centos" ]; then 88 | yum -y install curl > /dev/null 2>&1 89 | else 90 | apt-get -y install curl > /dev/null 2>&1 91 | fi 92 | 93 | 94 | # Install Besttrace 95 | if [ ! -e '/tmp/besttrace' ]; then 96 | echo "Installing Besttrace......" 97 | dir=$(pwd) 98 | cd /tmp/ 99 | wget -N --no-check-certificate https://raw.githubusercontent.com/FunctionClub/ZBench/master/besttrace > /dev/null 2>&1 100 | cd $dir 101 | fi 102 | chmod a+rx /tmp/besttrace 103 | 104 | # Check Python 105 | if [ ! -e '/usr/bin/python' ]; then 106 | echo "Installing Python......" 107 | if [ "${release}" == "centos" ]; then 108 | yum update > /dev/null 2>&1 109 | yum -y install python 110 | else 111 | apt-get update > /dev/null 2>&1 112 | apt-get -y install python 113 | fi 114 | fi 115 | 116 | # Install Speedtest 117 | if [ ! -e '/tmp/speedtest.py' ]; then 118 | echo "Installing SpeedTest......" 119 | dir=$(pwd) 120 | cd /tmp/ 121 | wget -N --no-check-certificate https://raw.github.com/sivel/speedtest-cli/master/speedtest.py > /dev/null 2>&1 122 | cd $dir 123 | fi 124 | chmod a+rx /tmp/speedtest.py 125 | 126 | 127 | # Install Zping 128 | if [ ! -e '/tmp/ZPing.py' ]; then 129 | echo "Installing ZPing.py......" 130 | dir=$(pwd) 131 | cd /tmp/ 132 | wget -N --no-check-certificate https://raw.githubusercontent.com/FunctionClub/ZBench/master/ZPing.py > /dev/null 2>&1 133 | cd $dir 134 | fi 135 | chmod a+rx /tmp/ZPing.py 136 | 137 | #"TraceRoute to Shanghai Telecom" 138 | /tmp/besttrace 61.129.42.6 > /tmp/sht.txt 2>&1 & 139 | #"TraceRoute to Shanghai Mobile" 140 | /tmp/besttrace speedtest2.sh.chinamobile.com > /tmp/shm.txt 2>&1 & 141 | #"TraceRoute to Shanghai Unicom" 142 | /tmp/besttrace 210.22.80.1 > /tmp/shu.txt 2>&1 & 143 | #"TraceRoute to Guangdong Telecom" 144 | /tmp/besttrace 121.14.220.240 > /tmp/gdt.txt 2>&1 & 145 | #"TraceRoute to Guangdong Mobile" 146 | /tmp/besttrace 211.136.192.6 > /tmp/gdm.txt 2>&1 & 147 | #"TraceRoute to Guangdong Unicom" 148 | /tmp/besttrace 221.5.88.88 > /tmp/gdu.txt 2>&1 & 149 | #"TraceRoute to Owner's Network" 150 | /tmp/besttrace ${OwnerIP} > /tmp/own.txt 2>&1 & 151 | 152 | 153 | 154 | 155 | get_opsy() { 156 | [ -f /etc/redhat-release ] && awk '{print ($1,$3~/^[0-9]/?$3:$4)}' /etc/redhat-release && return 157 | [ -f /etc/os-release ] && awk -F'[= "]' '/PRETTY_NAME/{print $3,$4,$5}' /etc/os-release && return 158 | [ -f /etc/lsb-release ] && awk -F'[="]+' '/DESCRIPTION/{print $2}' /etc/lsb-release && return 159 | } 160 | 161 | next() { 162 | printf "%-74s\n" "-" | sed 's/\s/-/g' 163 | } 164 | 165 | speed_test() { 166 | local speedtest=$(wget -4O /dev/null -T300 $1 2>&1 | awk '/\/dev\/null/ {speed=$3 $4} END {gsub(/\(|\)/,"",speed); print speed}') 167 | local ipaddress=$(ping -c1 -n `awk -F'/' '{print $3}' <<< $1` | awk -F'[()]' '{print $2;exit}') 168 | local nodeName=$2 169 | local latency=$(ping $ipaddress -c 3 | grep avg | awk -F / '{print $5}')" ms" 170 | printf "${YELLOW}%-26s${GREEN}%-18s${RED}%-20s${SKYBLUE}%-12s${PLAIN}\n" "${nodeName}" "${ipaddress}" "${speedtest}" "${latency}" 171 | 172 | #Record Speed Data 173 | echo ${ipaddress} >> /tmp/speed.txt 174 | echo ${speedtest} >> /tmp/speed.txt 175 | echo ${latency} >> /tmp/speed.txt 176 | } 177 | 178 | speed() { 179 | rm -rf /tmp/speed.txt && touch /tmp/speed.txt 180 | speed_test 'http://cachefly.cachefly.net/100mb.test' 'CacheFly' 181 | speed_test 'http://speedtest.tokyo.linode.com/100MB-tokyo.bin' 'Linode, Tokyo, JP' 182 | speed_test 'http://speedtest.singapore.linode.com/100MB-singapore.bin' 'Linode, Singapore, SG' 183 | speed_test 'http://speedtest.london.linode.com/100MB-london.bin' 'Linode, London, UK' 184 | speed_test 'http://speedtest.frankfurt.linode.com/100MB-frankfurt.bin' 'Linode, Frankfurt, DE' 185 | speed_test 'http://speedtest.fremont.linode.com/100MB-fremont.bin' 'Linode, Fremont, CA' 186 | speed_test 'http://speedtest.dal05.softlayer.com/downloads/test100.zip' 'Softlayer, Dallas, TX' 187 | speed_test 'http://speedtest.sea01.softlayer.com/downloads/test100.zip' 'Softlayer, Seattle, WA' 188 | speed_test 'http://speedtest.fra02.softlayer.com/downloads/test100.zip' 'Softlayer, Frankfurt, DE' 189 | speed_test 'http://speedtest.sng01.softlayer.com/downloads/test100.zip' 'Softlayer, Singapore, SG' 190 | speed_test 'http://speedtest.hkg02.softlayer.com/downloads/test100.zip' 'Softlayer, HongKong, CN' 191 | } 192 | 193 | speed_test_cn(){ 194 | if [[ $1 == '' ]]; then 195 | temp=$(python /tmp/speedtest.py --share 2>&1) 196 | is_down=$(echo "$temp" | grep 'Download') 197 | if [[ ${is_down} ]]; then 198 | local REDownload=$(echo "$temp" | awk -F ':' '/Download/{print $2}') 199 | local reupload=$(echo "$temp" | awk -F ':' '/Upload/{print $2}') 200 | local relatency=$(echo "$temp" | awk -F ':' '/Hosted/{print $2}') 201 | local nodeName=$2 202 | 203 | printf "${YELLOW}%-25s${GREEN}%-18s${RED}%-20s${SKYBLUE}%-12s${PLAIN}\n" "${nodeName}" "${reupload}" "${REDownload}" "${relatency}" 204 | else 205 | local cerror="ERROR" 206 | fi 207 | else 208 | temp=$(python /tmp/speedtest.py --server $1 --share 2>&1) 209 | is_down=$(echo "$temp" | grep 'Download') 210 | if [[ ${is_down} ]]; then 211 | local REDownload=$(echo "$temp" | awk -F ':' '/Download/{print $2}') 212 | local reupload=$(echo "$temp" | awk -F ':' '/Upload/{print $2}') 213 | local relatency=$(echo "$temp" | awk -F ':' '/Hosted/{print $2}') 214 | temp=$(echo "$relatency" | awk -F '.' '{print $1}') 215 | if [[ ${temp} -gt 1000 ]]; then 216 | relatency=" 000.000 ms" 217 | fi 218 | local nodeName=$2 219 | 220 | printf "${YELLOW}%-25s${GREEN}%-18s${RED}%-20s${SKYBLUE}%-12s${PLAIN}\n" "${nodeName}" "${reupload}" "${REDownload}" "${relatency}" 221 | else 222 | local cerror="ERROR" 223 | fi 224 | fi 225 | 226 | #Record Speed_cn Data 227 | echo ${reupload} >> /tmp/speed_cn.txt 228 | echo ${REDownload} >> /tmp/speed_cn.txt 229 | echo ${relatency} >> /tmp/speed_cn.txt 230 | 231 | 232 | } 233 | 234 | speed_cn() { 235 | rm -rf /tmp/speed_cn.txt && touch /tmp/speed_cn.txt 236 | 237 | speed_test_cn '12637' 'Xiangyang CT' 238 | speed_test_cn '3633' 'Shanghai CT' 239 | speed_test_cn '4624' 'Chengdu CT' 240 | speed_test_cn '4863' "Xi'an CU" 241 | speed_test_cn '5083' 'Shanghai CU' 242 | speed_test_cn '5726' 'Chongqing CU' 243 | speed_test_cn '5192' "Beijing CT" 244 | speed_test_cn '4665' 'Beijing CT' 245 | speed_test_cn '4575' 'Hunan CT' 246 | 247 | rm -rf /tmp/speedtest.py 248 | } 249 | 250 | 251 | io_test() { 252 | (LANG=C dd if=/dev/zero of=test_$$ bs=64k count=16k conv=fdatasync && rm -f test_$$ ) 2>&1 | awk -F, '{io=$NF} END { print io}' | sed 's/^[ \t]*//;s/[ \t]*$//' 253 | } 254 | 255 | calc_disk() { 256 | local total_size=0 257 | local array=$@ 258 | for size in ${array[@]} 259 | do 260 | [ "${size}" == "0" ] && size_t=0 || size_t=`echo ${size:0:${#size}-1}` 261 | [ "`echo ${size:(-1)}`" == "K" ] && size=0 262 | [ "`echo ${size:(-1)}`" == "M" ] && size=$( awk 'BEGIN{printf "%.1f", '$size_t' / 1024}' ) 263 | [ "`echo ${size:(-1)}`" == "T" ] && size=$( awk 'BEGIN{printf "%.1f", '$size_t' * 1024}' ) 264 | [ "`echo ${size:(-1)}`" == "G" ] && size=${size_t} 265 | total_size=$( awk 'BEGIN{printf "%.1f", '$total_size' + '$size'}' ) 266 | done 267 | echo ${total_size} 268 | } 269 | 270 | cname=$( awk -F: '/model name/ {name=$2} END {print name}' /proc/cpuinfo | sed 's/^[ \t]*//;s/[ \t]*$//' ) 271 | cores=$( awk -F: '/model name/ {core++} END {print core}' /proc/cpuinfo ) 272 | freq=$( awk -F: '/cpu MHz/ {freq=$2} END {print freq}' /proc/cpuinfo | sed 's/^[ \t]*//;s/[ \t]*$//' ) 273 | tram=$( free -m | awk '/Mem/ {print $2}' ) 274 | uram=$( free -m | awk '/Mem/ {print $3}' ) 275 | swap=$( free -m | awk '/Swap/ {print $2}' ) 276 | uswap=$( free -m | awk '/Swap/ {print $3}' ) 277 | 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 ) 278 | load=$( w | head -1 | awk -F'load average:' '{print $2}' | sed 's/^[ \t]*//;s/[ \t]*$//' ) 279 | opsy=$( get_opsy ) 280 | arch=$( uname -m ) 281 | lbit=$( getconf LONG_BIT ) 282 | kern=$( uname -r ) 283 | ipv6=$( wget -qO- -t1 -T2 ipv6.icanhazip.com ) 284 | disk_size1=($( LANG=C df -hPl | grep -wvE '\-|none|tmpfs|devtmpfs|by-uuid|chroot|Filesystem' | awk '{print $2}' )) 285 | disk_size2=($( LANG=C df -hPl | grep -wvE '\-|none|tmpfs|devtmpfs|by-uuid|chroot|Filesystem' | awk '{print $3}' )) 286 | disk_total_size=$( calc_disk ${disk_size1[@]} ) 287 | disk_used_size=$( calc_disk ${disk_size2[@]} ) 288 | 289 | 290 | clear 291 | next 292 | echo -e "CPU model : ${SKYBLUE}$cname${PLAIN}" 293 | echo -e "Number of cores : ${SKYBLUE}$cores${PLAIN}" 294 | echo -e "CPU frequency : ${SKYBLUE}$freq MHz${PLAIN}" 295 | echo -e "Total size of Disk : ${SKYBLUE}$disk_total_size GB ($disk_used_size GB Used)${PLAIN}" 296 | echo -e "Total amount of Mem : ${SKYBLUE}$tram MB ($uram MB Used)${PLAIN}" 297 | echo -e "Total amount of Swap : ${SKYBLUE}$swap MB ($uswap MB Used)${PLAIN}" 298 | echo -e "System uptime : ${SKYBLUE}$up${PLAIN}" 299 | echo -e "Load average : ${SKYBLUE}$load${PLAIN}" 300 | echo -e "OS : ${SKYBLUE}$opsy${PLAIN}" 301 | echo -e "Arch : ${SKYBLUE}$arch ($lbit Bit)${PLAIN}" 302 | echo -e "Kernel : ${SKYBLUE}$kern${PLAIN}" 303 | echo -ne "Virt : " 304 | virtua=$(virt-what) 2>/dev/null 305 | 306 | if [[ ${virtua} ]]; then 307 | echo -e "${SKYBLUE}$virtua${PLAIN}" 308 | else 309 | virtua="No Virt" 310 | echo -e "${SKYBLUE}No Virt${PLAIN}" 311 | fi 312 | 313 | next 314 | io1=$( io_test ) 315 | echo -e "I/O speed(1st run) :${YELLOW}$io1${PLAIN}" 316 | io2=$( io_test ) 317 | echo -e "I/O speed(2nd run) :${YELLOW}$io2${PLAIN}" 318 | io3=$( io_test ) 319 | echo -e "I/O speed(3rd run) :${YELLOW}$io3${PLAIN}" 320 | next 321 | 322 | 323 | ##Record All Test data 324 | rm -rf /tmp/info.txt 325 | touch /tmp/info.txt 326 | echo $cname >> /tmp/info.txt 327 | echo $cores >> /tmp/info.txt 328 | echo $freq MHz >> /tmp/info.txt 329 | echo "$disk_total_size GB ($disk_used_size GB 已使用) ">> /tmp/info.txt 330 | echo "$tram MB ($uram MB 已使用) ">> /tmp/info.txt 331 | echo "$swap MB ($uswap MB 已使用)" >> /tmp/info.txt 332 | echo $up >> /tmp/info.txt 333 | echo $load >> /tmp/info.txt 334 | echo $opsy >> /tmp/info.txt 335 | echo "$arch ($lbit 位) ">> /tmp/info.txt 336 | echo $kern >> /tmp/info.txt 337 | echo $virtua >> /tmp/info.txt 338 | echo $io1 >> /tmp/info.txt 339 | echo $io2 >> /tmp/info.txt 340 | echo $io3 >> /tmp/info.txt 341 | AKEY=$( uuid ) 342 | 343 | printf "%-26s%-18s%-20s%-12s\n" "Node Name" "IP Address" "Download Speed" "Latency" 344 | speed && next 345 | printf "%-26s%-18s%-20s%-12s\n" "Node Name" "Upload Speed" "Download Speed" "Latency" 346 | speed_cn && next 347 | python /tmp/ZPing.py 348 | next 349 | 350 | 351 | 352 | NetCFspeec=$( sed -n "2p" /tmp/speed.txt ) 353 | NetCFping=$( sed -n "3p" /tmp/speed.txt ) 354 | NetLJPspeed=$( sed -n "5p" /tmp/speed.txt ) 355 | NetLJPping=$( sed -n "6p" /tmp/speed.txt ) 356 | NetLSGspeed=$( sed -n "8p" /tmp/speed.txt ) 357 | NetLSGping=$( sed -n "9p" /tmp/speed.txt ) 358 | NetLUKspeed=$( sed -n "11p" /tmp/speed.txt ) 359 | NetLUKping=$( sed -n "12p" /tmp/speed.txt ) 360 | NetLDEspeed=$( sed -n "14p" /tmp/speed.txt ) 361 | NetLDEping=$( sed -n "15p" /tmp/speed.txt ) 362 | NetLCAspeed=$( sed -n "17p" /tmp/speed.txt ) 363 | NetLCAping=$( sed -n "18p" /tmp/speed.txt ) 364 | NetSTXspeed=$( sed -n "20p" /tmp/speed.txt ) 365 | NetSTXping=$( sed -n "21p" /tmp/speed.txt ) 366 | NetSWAspeed=$( sed -n "23p" /tmp/speed.txt ) 367 | NetSWAping=$( sed -n "24p" /tmp/speed.txt ) 368 | NetSDEspeed=$( sed -n "26p" /tmp/speed.txt ) 369 | NetSDEping=$( sed -n "27p" /tmp/speed.txt ) 370 | NetSSGspeed=$( sed -n "29p" /tmp/speed.txt ) 371 | NetSSGping=$( sed -n "30p" /tmp/speed.txt ) 372 | NetSCNspeed=$( sed -n "32p" /tmp/speed.txt ) 373 | NetSCNping=$( sed -n "33p" /tmp/speed.txt ) 374 | 375 | 376 | NetUPST=$( sed -n "4p" /tmp/speed_cn.txt ) 377 | NetDWST=$( sed -n "5p" /tmp/speed_cn.txt ) 378 | NetPiST=$( sed -n "6p" /tmp/speed_cn.txt ) 379 | NetUPCT=$( sed -n "7p" /tmp/speed_cn.txt ) 380 | NetDWCT=$( sed -n "8p" /tmp/speed_cn.txt ) 381 | NetPiCT=$( sed -n "9p" /tmp/speed_cn.txt ) 382 | NetUPXT=$( sed -n "10p" /tmp/speed_cn.txt ) 383 | NetDWXT=$( sed -n "11p" /tmp/speed_cn.txt ) 384 | NetPiXT=$( sed -n "12p" /tmp/speed_cn.txt ) 385 | NetUPSU=$( sed -n "13p" /tmp/speed_cn.txt ) 386 | NetDWSU=$( sed -n "14p" /tmp/speed_cn.txt ) 387 | NetPiSU=$( sed -n "15p" /tmp/speed_cn.txt ) 388 | NetUPCU=$( sed -n "16p" /tmp/speed_cn.txt ) 389 | NetDWCU=$( sed -n "17p" /tmp/speed_cn.txt ) 390 | NetPiCU=$( sed -n "18p" /tmp/speed_cn.txt ) 391 | NetUPXM=$( sed -n "19p" /tmp/speed_cn.txt ) 392 | NetDWXM=$( sed -n "20p" /tmp/speed_cn.txt ) 393 | NetPiXM=$( sed -n "21p" /tmp/speed_cn.txt ) 394 | NetUPSM=$( sed -n "22p" /tmp/speed_cn.txt ) 395 | NetDWSM=$( sed -n "23p" /tmp/speed_cn.txt ) 396 | NetPiSM=$( sed -n "24p" /tmp/speed_cn.txt ) 397 | NetUPCM=$( sed -n "25p" /tmp/speed_cn.txt ) 398 | NetDWCM=$( sed -n "26p" /tmp/speed_cn.txt ) 399 | NetPiCM=$( sed -n "27p" /tmp/speed_cn.txt ) 400 | 401 | 402 | wget -N --no-check-certificate https://raw.githubusercontent.com/FunctionClub/ZBench/master/Generate.py >> /dev/null 2>&1 403 | python Generate.py && rm -rf Generate.py && cp /root/report.html /tmp/report/index.html 404 | TSM=$( cat /tmp/shm.txt_table ) 405 | TST=$( cat /tmp/sht.txt_table ) 406 | TSU=$( cat /tmp/shu.txt_table ) 407 | TGM=$( cat /tmp/gdm.txt_table ) 408 | TGT=$( cat /tmp/gdt.txt_table ) 409 | TGU=$( cat /tmp/gdu.txt_table ) 410 | curl 'http://api.zbench.kirito.moe/action.php' --data "CPUmodel=$cname &CPUspeed=$freq MHz &CPUcore=$cores &HDDsize=$disk_total_size GB ($disk_used_size GB 已使用) &RAMsize=$tram MB ($uram MB 已使用)&SWAPsize=$swap MB ($uswap MB 已使用)&UPtime= $up&Arch=1&systemload=$load&OS= $opsy &Arch=$arch ($lbit 位)&Kernel=$kern &Virmethod=$virtua &IOa=$io1&IOb=$io2&IOc=$io3&NetCFspeec=$NetCFspeec&NetCFping=$NetCFping&NetLJPspeed=$NetLJPspeed&NetLJPping=$NetLJPping&NetLSGspeed=$NetLSGspeed&NetLSGping=$NetLSGping&NetLUKspeed=$NetLUKspeed&NetLUKping=$NetLUKping&NetLDEspeed=$NetLDEspeed&NetLDEping=$NetLDEping&NetLCAspeed=$NetLCAspeed&NetLCAping=$NetLCAping&NetSTXspeed=$NetSTXspeed&NetSTXping=$NetSTXping&NetSWAspeed=$NetSWAspeed&NetSWAping=$NetSWAping&NetSDEspeed=$NetSDEspeed&NetSDEping=$NetSDEping&NetSSGspeed=$NetSSGspeed&NetSSGping=$NetSSGping&NetSCNspeed=$NetSCNspeed&NetSCNping=$NetSCNping&NetUPST=$NetUPST&NetDWST=$NetDWST&NetPiST=$NetPiST&NetUPCT=$NetUPCT&NetDWCT=$NetDWCT&NetPiCT=$NetPiCT&NetUPXT=$NetUPXT&NetDWXT=$NetDWXT&NetPiXT=$NetPiXT&NetUPSU=$NetUPSU&NetDWSU=$NetDWSU&NetPiSU=$NetPiSU&NetUPCU=$NetUPCU&NetDWCU=$NetDWCU&NetPiCU=$NetPiCU&NetUPXM=$NetUPXM&NetDWXM=$NetDWXM&NetPiXM=$NetPiXM&NetUPSM=$NetUPSM&NetDWSM=$NetDWSM&NetPiSM=$NetPiSM&NetUPCM=$NetUPCM&NetDWCM=$NetDWCM&NetPiCM=$NetPiCM&TSM=$TSM&TST=$TST&TSU=$TSU&TGM=$TGM&TGT=$TGT&TGU=$TGU&AKEY=$AKEY&Provider=$Provider" 411 | 412 | IKEY=$(curl "http://api.zbench.kirito.moe/getkey.php?AKEY=$AKEY" 2>/dev/null) 413 | echo "Result Address:https://zbench.kirito.moe/record.php?IKEY=$IKEY" 414 | echo "Your bench data is saved to /root/report.html" 415 | 416 | # If use simple http server 417 | while :; do echo 418 | read -p "Do you want to check your Test Report? [y/n]: " ifreport 419 | if [[ ! $ifreport =~ ^[y,n]$ ]]; then 420 | echo "Input error! Please only input 'y' or 'n'" 421 | else 422 | break 423 | fi 424 | done 425 | 426 | if [[ $ifreport == 'y' ]];then 427 | echo "" 428 | myip=`curl -m 10 -s http://members.3322.org/dyndns/getip` 429 | echo "Visit http://${myip}:8001/index.html to see your report,Press Ctrl + C to exit." 430 | cd /tmp/report 431 | python -m SimpleHTTPServer 8001 432 | iptables -I INPUT -m state --state NEW -m tcp -p tcp --dport 8001 -j ACCEPT 433 | fi 434 | -------------------------------------------------------------------------------- /ZPing-CN.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python 2 | # -*- coding: UTF-8 -*- 3 | ''' 4 | Author 雨落无声(Github: https://github.com/ylws-4617) 5 | Reference: 6 | 1. https://www.s0nnet.com/archives/python-icmp 7 | 2. http://www.pythoner.com/357.html 8 | ''' 9 | 10 | import commands 11 | 12 | def ping(host): 13 | cmd = "ping "+ str(host) + " -c2 -W 2" 14 | result = commands.getoutput(cmd) 15 | result = result.split() 16 | result = result[-2].split("/")[0] 17 | if result.isalpha(): 18 | result = False 19 | return float(result) 20 | 21 | 22 | STYLE = { 23 | 'fore': { 24 | 'black': 30, 'red': 31, 'green': 32, 'yellow': 33, 25 | 'blue': 34, 'purple': 35, 'cyan': 36, 'white': 37, 26 | }, 27 | 'back': { 28 | 'black': 40, 'red': 41, 'green': 42, 'yellow': 43, 29 | 'blue': 44, 'purple': 45, 'cyan': 46, 'white': 47, 30 | }, 31 | 'mode': { 32 | 'bold': 1, 'underline': 4, 'blink': 5, 'invert': 7, 33 | }, 34 | 'default': { 35 | 'end': 0, 36 | } 37 | } 38 | 39 | 40 | def use_style(string, mode='', fore='', back=''): 41 | mode = '%s' % STYLE['mode'][mode] if STYLE['mode'].has_key(mode) else '' 42 | fore = '%s' % STYLE['fore'][fore] if STYLE['fore'].has_key(fore) else '' 43 | back = '%s' % STYLE['back'][back] if STYLE['back'].has_key(back) else '' 44 | style = ';'.join([s for s in [mode, fore, back] if s]) 45 | style = '\033[%sm' % style if style else '' 46 | end = '\033[%sm' % STYLE['default']['end'] if style else '' 47 | return '%s%s%s' % (style, string, end) 48 | 49 | D = { 50 | '郑州': '61.168.23.74', 51 | '济南': '202.102.152.3', 52 | '天津': '219.150.32.132', 53 | '昌吉': '61.128.107.242', 54 | '拉萨': '221.13.70.244', 55 | '长春': '202.98.0.68', 56 | '深圳': '119.147.52.35', 57 | '兰州': 'www.lanzhouunicom.com', 58 | '西宁': '221.207.32.94', 59 | '合肥': '112.122.10.26', 60 | '武汉': '113.57.249.2', 61 | '襄阳': '202.103.44.150', 62 | '南昌': 'speedtest2.wy.jxunicom.com', 63 | '重庆': 'speedtest1.cqccn.com', 64 | '上海': 'speedtest2.sh.chinamobile.com', 65 | '呼和浩特': '222.74.1.200 ', 66 | '乌鲁木齐': '61.128.114.133', 67 | '杭州': '122.229.136.10', 68 | '西安': 'xatest.wo-xa.com', 69 | '宁波': '202.96.104.1', 70 | '太原': 'speedtest.sxunicomjzjk.cn', 71 | '苏州': '218.94.214.42', 72 | '长沙': '61.234.254.5', 73 | '哈尔滨': '202.97.224.1', 74 | '北京': 'st1.bjtelecom.net', 75 | '成都': 'speed.westidc.com.cn', 76 | '沈阳': 'speedtest1.online.ln.cn', 77 | '南京': '4gnanjing1.speedtest.jsinfo.net', 78 | '宁夏': '221.199.9.35', 79 | '福州': 'upload1.testspeed.kaopuyun.com' 80 | } 81 | 82 | 83 | 84 | string =list() 85 | d=dict() 86 | 87 | for x in D: 88 | host=D[x] 89 | result = ping(host) 90 | 91 | 92 | if result == False: 93 | latency_str = use_style(str("Fail"), fore='red') 94 | elif float(result) <= 60: 95 | latency_str =use_style(str(round(result,2)) + " ms",fore='green') 96 | elif float(result) <= 130: 97 | latency_str = use_style(str(round(result,2))+" ms",fore='yellow') 98 | else: 99 | latency_str = use_style(str(round(result,2))+" ms", fore='red') 100 | 101 | d[x] = float(result) 102 | 103 | string.append((x,latency_str)) 104 | if len(string) == 3: 105 | l1 = str(int(len(string[0][0])/3+12)) 106 | l2 = str(int(len(string[1][0])/3+12)) 107 | l3 = str(int(len(string[2][0])/3+12)) 108 | mystring = "{0:"+l1+"}: {1:20}{2:"+l2+"}: {3:20}{4:"+l3+"}: {5:20}" 109 | print(mystring.format(string[0][0],string[0][1],string[1][0],string[1][1],string[2][0],string[2][1])) 110 | string = list() 111 | 112 | 113 | if len(string) == 2: 114 | l1 = str(int(len(string[0][0])/3+12)) 115 | l2 = str(int(len(string[1][0])/3+12)) 116 | mystring = "{0:"+l1+"}: {1:20}{2:"+l2+"}: {3:20}" 117 | print(mystring.format(string[0][0],string[0][1],string[1][0],string[1][1])) 118 | 119 | if len(string) == 1: 120 | l1 = str(int(len(string[0][0])/3+12)) 121 | mystring = "{0:"+l1+"}: {1:20}" 122 | print(mystring.format(string[0][0],string[0][1])) 123 | 124 | -------------------------------------------------------------------------------- /ZPing.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python 2 | # -*- coding: UTF-8 -*- 3 | ''' 4 | Author 雨落无声(Github: https://github.com/ylws-4617) 5 | Reference: 6 | 1. https://www.s0nnet.com/archives/python-icmp 7 | 2. http://www.pythoner.com/357.html 8 | ''' 9 | 10 | import commands 11 | 12 | def ping(host): 13 | cmd = "ping "+ str(host) + " -c2 -W 2" 14 | result = commands.getoutput(cmd) 15 | result = result.split() 16 | result = result[-2].split("/")[0] 17 | if result.isalpha(): 18 | result = False 19 | return float(result) 20 | 21 | STYLE = { 22 | 'fore': { 23 | 'black': 30, 'red': 31, 'green': 32, 'yellow': 33, 24 | 'blue': 34, 'purple': 35, 'cyan': 36, 'white': 37, 25 | }, 26 | 'back': { 27 | 'black': 40, 'red': 41, 'green': 42, 'yellow': 43, 28 | 'blue': 44, 'purple': 45, 'cyan': 46, 'white': 47, 29 | }, 30 | 'mode': { 31 | 'bold': 1, 'underline': 4, 'blink': 5, 'invert': 7, 32 | }, 33 | 'default': { 34 | 'end': 0, 35 | } 36 | } 37 | 38 | 39 | def use_style(string, mode='', fore='', back=''): 40 | mode = '%s' % STYLE['mode'][mode] if STYLE['mode'].has_key(mode) else '' 41 | fore = '%s' % STYLE['fore'][fore] if STYLE['fore'].has_key(fore) else '' 42 | back = '%s' % STYLE['back'][back] if STYLE['back'].has_key(back) else '' 43 | style = ';'.join([s for s in [mode, fore, back] if s]) 44 | style = '\033[%sm' % style if style else '' 45 | end = '\033[%sm' % STYLE['default']['end'] if style else '' 46 | return '%s%s%s' % (style, string, end) 47 | 48 | D = { 49 | 'Zhengzhou': '61.168.23.74', 50 | 'Jinan': '202.102.152.3', 51 | 'Tianjin': '219.150.32.132', 52 | 'Changji': '61.128.107.242', 53 | 'Lhasa': '221.13.70.244', 54 | 'Changchun': '202.98.0.68', 55 | 'Shenzhen': '119.147.52.35', 56 | 'Lanzhou': 'www.lanzhouunicom.com', 57 | 'Xining': '221.207.32.94', 58 | 'Hefei': '112.122.10.26', 59 | 'Wuhan': '113.57.249.2', 60 | 'Xiangyang': '202.103.44.150', 61 | 'Nanchang': 'speedtest2.wy.jxunicom.com', 62 | 'Chongqing': 'speedtest1.cqccn.com', 63 | 'Shanghai': 'speedtest2.sh.chinamobile.com', 64 | 'Huhehaote': '222.74.1.200', 65 | 'Urumqi': '61.128.114.133', 66 | 'Hangzhou': '122.229.136.10', 67 | 'Xi an': 'xatest.wo-xa.com', 68 | 'Ningbo': '202.96.104.1', 69 | 'Taiyuan': 'speedtest.sxunicomjzjk.cn', 70 | 'Suzhou': '218.94.214.42', 71 | 'Changsha': '61.234.254.5', 72 | 'Harbin': '202.97.224.1', 73 | 'Beijing': 'st1.bjtelecom.net', 74 | 'Chengdu': 'speed.westidc.com.cn', 75 | 'Shenyang': 'speedtest1.online.ln.cn', 76 | 'Nanjing': '4gnanjing1.speedtest.jsinfo.net', 77 | 'Ningxia': '221.199.9.35', 78 | 'Fuzhou': 'upload1.testspeed.kaopuyun.com' 79 | } 80 | 81 | 82 | string =list() 83 | d=dict() 84 | 85 | for x in D: 86 | host=D[x] 87 | result = ping(host) 88 | 89 | 90 | if result == False: 91 | latency_str = use_style(str("Fail"), fore='red') 92 | elif float(result) <= 60: 93 | latency_str =use_style(str(round(result,2)) + " ms",fore='green') 94 | elif float(result) <= 130: 95 | latency_str = use_style(str(round(result,2))+" ms",fore='yellow') 96 | else: 97 | latency_str = use_style(str(round(result,2))+" ms", fore='red') 98 | 99 | d[x] = float(result) 100 | 101 | string.append((x,latency_str)) 102 | if len(string) == 3: 103 | print("{0:12}: {1:20}{2:12}: {3:20}{4:12}: {5:20}".format(string[0][0],string[0][1],string[1][0],string[1][1],string[2][0],string[2][1])) 104 | string = list() 105 | 106 | 107 | if len(string) == 2: 108 | print("{0:12}: {1:20}{2:12}: {3:20}".format(string[0][0],string[0][1],string[1][0],string[1][1])) 109 | 110 | if len(string) == 1: 111 | print("{0:12}: {1:20}".format(string[0][0],string[0][1])) 112 | -------------------------------------------------------------------------------- /besttrace: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/FunctionClub/ZBench/fde6a7b932bccfd76124e176d98bec03b28e9160/besttrace --------------------------------------------------------------------------------