Advertisement
Guest User

speedtest.sh

a guest
Oct 16th, 2019
2,412
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 46.74 KB | None | 0 0
  1. #!/usr/bin/env bash
  2.  
  3. about() {
  4. echo ""
  5. echo " ========================================================= "
  6. echo " \ Speedtest geekbench / "
  7. echo " \ System info, Geekbench, I/O test and speedtest / "
  8. echo " \ v1.4.5 2019-10-13 / "
  9. echo " ========================================================= "
  10. echo ""
  11. }
  12.  
  13. cancel() {
  14. echo ""
  15. next;
  16. echo " Abort ..."
  17. echo " Cleanup ..."
  18. cleanup;
  19. echo " Done"
  20. exit
  21. }
  22.  
  23. trap cancel SIGINT
  24.  
  25. benchram="$HOME/tmpbenchram"
  26. NULL="/dev/null"
  27.  
  28. echostyle(){
  29. if hash tput 2>$NULL; then
  30. echo " $(tput setaf 6)$1$(tput sgr0)"
  31. echo " $1" >> $log
  32. else
  33. echo " $1" | tee -a $log
  34. fi
  35. }
  36.  
  37. benchinit() {
  38. # check release
  39. if [ -f /etc/redhat-release ]; then
  40. release="centos"
  41. elif cat /etc/issue | grep -Eqi "debian"; then
  42. release="debian"
  43. elif cat /etc/issue | grep -Eqi "ubuntu"; then
  44. release="ubuntu"
  45. elif cat /etc/issue | grep -Eqi "centos|red hat|redhat"; then
  46. release="centos"
  47. elif cat /proc/version | grep -Eqi "debian"; then
  48. release="debian"
  49. elif cat /proc/version | grep -Eqi "ubuntu"; then
  50. release="ubuntu"
  51. elif cat /proc/version | grep -Eqi "centos|red hat|redhat"; then
  52. release="centos"
  53. fi
  54.  
  55. # check OS
  56. #if [ "${release}" == "centos" ]; then
  57. # echo "Checking OS ... [ok]"
  58. #else
  59. # echo "Error: This script must be run on CentOS!"
  60. # exit 1
  61. #fi
  62. #echo -ne "\e[1A"; echo -ne "\e[0K\r"
  63.  
  64. # check root
  65. [[ $EUID -ne 0 ]] && echo -e "Error: This script must be run as root!" && exit 1
  66.  
  67.  
  68. # check python
  69. if [ ! -e '/usr/bin/python' ]; then
  70. echo " Installing Python2 ..."
  71. if [ "${release}" == "centos" ]; then
  72. yum update > /dev/null 2>&1
  73. yum -y install python2 > /dev/null 2>&1
  74. alternatives --set python /usr/bin/python2 > /dev/null 2>&1
  75. else
  76. apt-get update > /dev/null 2>&1
  77. apt-get -y install python > /dev/null 2>&1
  78. fi
  79. echo -ne "\e[1A"; echo -ne "\e[0K\r"
  80. fi
  81.  
  82. # check curl
  83. if [ ! -e '/usr/bin/curl' ]; then
  84. echo " Installing Curl ..."
  85. if [ "${release}" == "centos" ]; then
  86. yum update > /dev/null 2>&1
  87. yum -y install curl > /dev/null 2>&1
  88. else
  89. apt-get update > /dev/null 2>&1
  90. apt-get -y install curl > /dev/null 2>&1
  91. fi
  92. echo -ne "\e[1A"; echo -ne "\e[0K\r"
  93. fi
  94.  
  95. # check wget
  96. if [ ! -e '/usr/bin/wget' ]; then
  97. echo " Installing Wget ..."
  98. if [ "${release}" == "centos" ]; then
  99. yum update > /dev/null 2>&1
  100. yum -y install wget > /dev/null 2>&1
  101. else
  102. apt-get update > /dev/null 2>&1
  103. apt-get -y install wget > /dev/null 2>&1
  104. fi
  105. echo -ne "\e[1A"; echo -ne "\e[0K\r"
  106. fi
  107.  
  108. # check bzip2
  109. if [ ! -e '/usr/bin/bzip2' ]; then
  110. echo " Installing bzip2 ..."
  111. if [ "${release}" == "centos" ]; then
  112. yum update > /dev/null 2>&1
  113. yum -y install bzip2 > /dev/null 2>&1
  114. else
  115. apt-get update > /dev/null 2>&1
  116. apt-get -y install bzip2 > /dev/null 2>&1
  117. fi
  118. echo -ne "\e[1A"; echo -ne "\e[0K\r"
  119. fi
  120.  
  121. # install speedtest-cli
  122. if [ ! -e 'speedtest.py' ]; then
  123. echo " Installing Speedtest-cli ..."
  124. wget --no-check-certificate https://raw.github.com/sivel/speedtest-cli/master/speedtest.py > /dev/null 2>&1
  125. echo -ne "\e[1A"; echo -ne "\e[0K\r"
  126. fi
  127. chmod a+rx speedtest.py
  128.  
  129.  
  130. # install tools.py
  131. if [ ! -e 'tools.py' ]; then
  132. echo " Installing tools.py ..."
  133. wget --no-check-certificate https://raw.githubusercontent.com/laset-com/speedtest/master/tools.py > /dev/null 2>&1
  134. echo -ne "\e[1A"; echo -ne "\e[0K\r"
  135. fi
  136. chmod a+rx tools.py
  137.  
  138. sleep 5
  139.  
  140. # start
  141. start=$(date +%s)
  142. }
  143.  
  144. get_opsy() {
  145. [ -f /etc/redhat-release ] && awk '{print ($1,$3~/^[0-9]/?$3:$4)}' /etc/redhat-release && return
  146. [ -f /etc/os-release ] && awk -F'[= "]' '/PRETTY_NAME/{print $3,$4,$5}' /etc/os-release && return
  147. [ -f /etc/lsb-release ] && awk -F'[="]+' '/DESCRIPTION/{print $2}' /etc/lsb-release && return
  148. }
  149.  
  150. next() {
  151. printf "%-75s\n" "-" | sed 's/\s/-/g' | tee -a $log
  152. }
  153. next2() {
  154. printf "%-57s\n" "-" | sed 's/\s/-/g'
  155. }
  156.  
  157. delete() {
  158. echo -ne "\e[1A"; echo -ne "\e[0K\r"
  159. }
  160.  
  161. speed_test(){
  162. if [[ $1 == '' ]]; then
  163. temp=$(python speedtest.py --share 2>&1)
  164. is_down=$(echo "$temp" | grep 'Download')
  165. result_speed=$(echo "$temp" | awk -F ' ' '/results/{print $3}')
  166. if [[ ${is_down} ]]; then
  167. local REDownload=$(echo "$temp" | awk -F ':' '/Download/{print $2}')
  168. local reupload=$(echo "$temp" | awk -F ':' '/Upload/{print $2}')
  169. local relatency=$(echo "$temp" | awk -F ':' '/Hosted/{print $2}')
  170.  
  171. temp=$(echo "$relatency" | awk -F '.' '{print $1}')
  172. if [[ ${temp} -gt 50 ]]; then
  173. relatency="*"${relatency}
  174. fi
  175. local nodeName=$2
  176.  
  177. temp=$(echo "${REDownload}" | awk -F ' ' '{print $1}')
  178. if [[ $(awk -v num1=${temp} -v num2=0 'BEGIN{print(num1>num2)?"1":"0"}') -eq 1 ]]; then
  179. printf "%-17s%-17s%-17s%-7s\n" " ${nodeName}" "${reupload}" "${REDownload}" "${relatency}" | tee -a $log
  180. fi
  181. else
  182. local cerror="ERROR"
  183. fi
  184. else
  185. temp=$(python speedtest.py --server $1 --share 2>&1)
  186. is_down=$(echo "$temp" | grep 'Download')
  187. if [[ ${is_down} ]]; then
  188. local REDownload=$(echo "$temp" | awk -F ':' '/Download/{print $2}')
  189. local reupload=$(echo "$temp" | awk -F ':' '/Upload/{print $2}')
  190. #local relatency=$(echo "$temp" | awk -F ':' '/Hosted/{print $2}')
  191. local relatency=$(pingtest $3)
  192. #temp=$(echo "$relatency" | awk -F '.' '{print $1}')
  193. #if [[ ${temp} -gt 1000 ]]; then
  194. #relatency=" - "
  195. #fi
  196. local nodeName=$2
  197.  
  198. temp=$(echo "${REDownload}" | awk -F ' ' '{print $1}')
  199. if [[ $(awk -v num1=${temp} -v num2=0 'BEGIN{print(num1>num2)?"1":"0"}') -eq 1 ]]; then
  200. printf "%-17s%-17s%-17s%-7s\n" " ${nodeName}" "${reupload}" "${REDownload}" "${relatency}" | tee -a $log
  201. fi
  202. else
  203. local cerror="ERROR"
  204. fi
  205. fi
  206. }
  207.  
  208. print_speedtest() {
  209. echo "" | tee -a $log
  210. echostyle "## Global Speedtest"
  211. echo "" | tee -a $log
  212. printf "%-32s%-17s%-17s%-7s\n" " Location" "Upload" "Download" "Ping" | tee -a $log
  213. printf "%-75s\n" "-" | sed 's/\s/-/g' | tee -a $log
  214. speed_test '' 'Speedtest.net '
  215. speed_test '5029' 'USA, New York (AT&T) ' 'http://nyc.speedtest.sbcglobal.net'
  216. speed_test '17384' 'USA, Chicago (Windstream) ' 'http://chicago02.speedtest.windstream.net'
  217. speed_test '14238' 'USA, Dallas (Frontier) ' 'http://dallas.tx.speedtest.frontier.com'
  218. speed_test '14237' 'USA, Miami (Frontier) ' 'http://miami.fl.speedtest.frontier.com'
  219. speed_test '16974' 'USA, Los Angeles (Spectrum) ' 'http://speedtest.west.rr.com'
  220. speed_test '18189' 'UK, London (Community Fibre) ' 'http://sp01.ld8.lon.eng.communityfibre.co.uk'
  221. speed_test '27852' 'France, Lyon (SFR) ' 'http://cor2.speedtest.mire.sfr.net'
  222. speed_test '20507' 'Germany, Berlin (DNS:NET) ' 'http://speedtest01.dns-net.de'
  223. speed_test '1680' 'Spain, Madrid (Adamo) ' 'http://speedtest.mad.adamo.es'
  224. speed_test '395' 'Italy, Rome (Unidata) ' 'http://speedtest2.unidata.it'
  225. speed_test '1907' 'Russia, Moscow (MTS) ' 'http://librarian.comstar.ru'
  226. speed_test '2434' 'Israel, Haifa (013Netvision) ' 'http://speed2.013.net'
  227. speed_test '9930' 'India, New Delhi (Airtel) ' 'http://speedtestggn2.airtel.in'
  228. speed_test '7556' 'Singapore (FirstMedia) ' 'http://sg-speedtest.link.net.id'
  229. speed_test '7139' 'Japan, Tsukuba (SoftEther) ' 'http://speedtest2.softether.co.jp'
  230. speed_test '1267' 'Australia, Sydney (Yes Optus) ' 'http://s1.speedtest.syd.optusnet.com.au'
  231. speed_test '6591' 'RSA, Randburg (Cool Ideas) ' 'http://sp2.cisp.co.za'
  232. speed_test '11488' 'Brazil, Sao Paulo (Criare) ' 'http://ookla.spcom.net.br'
  233.  
  234. #rm -rf speedtest.py
  235. }
  236.  
  237. print_speedtest_usa() {
  238. echo "" | tee -a $log
  239. echostyle "## USA Speedtest"
  240. echo "" | tee -a $log
  241. printf "%-36s%-17s%-17s%-7s\n" " Location" "Upload" "Download" "Ping" | tee -a $log
  242. printf "%-75s\n" "-" | sed 's/\s/-/g' | tee -a $log
  243. speed_test '' 'Speedtest.net '
  244. speed_test '5029' 'USA, New York (AT&T) ' 'http://nyc.speedtest.sbcglobal.net'
  245. speed_test '13429' 'USA, Boston (Starry, Inc.) ' 'http://speedtest-server.starry.com'
  246. speed_test '5113' 'USA, Washington, DC (AT&T) ' 'http://was.speedtest.sbcglobal.net'
  247. speed_test '5028' 'USA, Charlotte, NC (AT&T) ' 'http://clt.speedtest.sbcglobal.net'
  248. speed_test '14231' 'USA, Atlanta (Frontier) ' 'http://atlanta.ga.speedtest.frontier.com'
  249. speed_test '14237' 'USA, Miami (Frontier) ' 'http://miami.fl.speedtest.frontier.com'
  250. speed_test '15779' 'USA, Nashville (Sprint) ' 'http://ookla1.nsvltn.sprintadp.net'
  251. speed_test '9560' 'USA, Indianapolis (Metronet) ' 'http://speedtest2.iplwin75.metronetinc.com'
  252. speed_test '5111' 'USA, Cleveland (AT&T) ' 'http://cle.speedtest.sbcglobal.net'
  253. speed_test '17384' 'USA, Chicago (Windstream) ' 'http://chicago02.speedtest.windstream.net'
  254. speed_test '5108' 'USA, St. Louis (AT&T) ' 'http://stl.speedtest.sbcglobal.net'
  255. speed_test '2917' 'USA, Minneapolis (US Internet)' 'http://speedtest.usiwireless.com'
  256. speed_test '17709' 'USA, Kansas City (UPNfiber) ' 'http://speedtest.upnfiber.com'
  257. speed_test '17751' 'USA, Oklahoma City (OneNet) ' 'http://okc-speedtest.onenet.net'
  258. speed_test '14238' 'USA, Dallas (Frontier) ' 'http://dallas.tx.speedtest.frontier.com'
  259. speed_test '5107' 'USA, San Antonio, TX (AT&T) ' 'http://sat.speedtest.sbcglobal.net'
  260. speed_test '19124' 'USA, Denver (Vistabeam) ' 'http://ookla-denver.vistabeam.com'
  261. speed_test '16869' 'USA, Albuquerque (Plateau Tel)' 'http://speedtest4.plateautel.net'
  262. speed_test '16613' 'USA, Phoenix (Cox) ' 'http://speedtest.rd.ph.cox.net'
  263. speed_test '2206' 'USA, Salt Lake City (UTOPIA) ' 'http://speedtest2.utopiafiber.net'
  264. speed_test '7878' 'USA, Helena, MT (The Fusion) ' 'http://helenast2.northcentraltower.com'
  265. speed_test '16622' 'USA, Las Vegas (Cox) ' 'http://speedtest.rd.lv.cox.net'
  266. speed_test '8879' 'USA, Seattle (Sprint) ' 'http://perftools2.sttlwa.sprintadp.net'
  267. speed_test '5026' 'USA, San Francisco (AT&T) ' 'http://sfo.speedtest.sbcglobal.net'
  268. speed_test '16974' 'USA, Los Angeles (Spectrum) ' 'http://speedtest.west.rr.com'
  269. speed_test '980' 'USA, Anchorage (Alaska Com) ' 'http://speedtest.anc.acsalaska.net'
  270. speed_test '16975' 'USA, Mililani, HI (Spectrum) ' 'http://speedtest.oceanic.com'
  271.  
  272. #rm -rf speedtest.py
  273. }
  274.  
  275. print_speedtest_europe() {
  276. echo "" | tee -a $log
  277. echostyle "## Europe Speedtest"
  278. echo "" | tee -a $log
  279. printf "%-34s%-17s%-17s%-7s\n" " Location" "Upload" "Download" "Ping" | tee -a $log
  280. printf "%-75s\n" "-" | sed 's/\s/-/g' | tee -a $log
  281. speed_test '' 'Speedtest.net '
  282. speed_test '1041' 'Ireland, Dublin (Digiweb) ' 'http://speedtest.digiweb.ie'
  283. speed_test '18189' 'UK, London (Community Fibre) ' 'http://sp01.ld8.lon.eng.communityfibre.co.uk'
  284. speed_test '26764' 'Netherlands, Amsterdam (MaxiTEL)' 'http://speedtest.as61349.net'
  285. speed_test '20507' 'Germany, Berlin (DNS:NET) ' 'http://speedtest01.dns-net.de'
  286. speed_test '27345' 'Germany, Munich (InterNetX) ' 'http://speedtest.internetx.de'
  287. speed_test '8751' 'Denmark, Copenhagen (Fiberby) ' 'http://speedtest.internetx.de'
  288. speed_test '26852' 'Sweden, Stockholm (SUNET) ' 'http://fd.sunet.se'
  289. speed_test '8018' 'Norway, Oslo (NextGenTel) ' 'http://sp2.nextgentel.no'
  290. speed_test '27852' 'France, Lyon (SFR) ' 'http://cor2.speedtest.mire.sfr.net'
  291. speed_test '1680' 'Spain, Madrid (Adamo) ' 'http://speedtest.mad.adamo.es'
  292. speed_test '8160' 'Portugal, Lisbon (Evolute) ' 'http://speedtest1.evolute.pt'
  293. speed_test '395' 'Italy, Rome (Unidata) ' 'http://speedtest2.unidata.it'
  294. speed_test '21194' 'Czechia, Prague (365internet) ' 'http://speedtest.365internet.cz'
  295. speed_test '15152' 'Austria, Vienna (Fonira) ' 'http://speedtest.fonira.at'
  296. speed_test '4166' 'Poland, Warsaw (Orange) ' 'http://war-o2.speedtest.orange.pl'
  297. speed_test '691' 'Slovakia, Kosice (ANTIK) ' 'http://speedtest.antik.sk'
  298. speed_test '6446' 'Ukraine, Kyiv (KyivStar) ' 'http://www.speedtest2.kyivstar.ua'
  299. speed_test '5834' 'Latvia, Riga (Bite) ' 'http://speedtest2.bite.lv'
  300. speed_test '4231' 'Russia, St.Petersburg (Prometey)' 'http://speedtest1.ptspb.net'
  301. speed_test '1907' 'Russia, Moscow (MTS) ' 'http://librarian.comstar.ru'
  302. speed_test '4590' 'Romania, Bucharest (Orange) ' 'http://speedtestbuc.orangero.net'
  303. speed_test '1727' 'Greece, Athens (GRNET) ' 'http://speed-test.gr-ix.gr'
  304. speed_test '23316' 'Turkey, Istanbul (Radore) ' 'http://speedtest.radore.com'
  305.  
  306. #rm -rf speedtest.py
  307. }
  308.  
  309. print_speedtest_asia() {
  310. echo "" | tee -a $log
  311. echostyle "## Asia Speedtest"
  312. echo "" | tee -a $log
  313. printf "%-34s%-17s%-17s%-7s\n" " Location" "Upload" "Download" "Ping" | tee -a $log
  314. printf "%-75s\n" "-" | sed 's/\s/-/g' | tee -a $log
  315. speed_test '' 'Speedtest.net '
  316. speed_test '9930' 'India, New Delhi (Airtel) ' 'http://speedtestggn2.airtel.in'
  317. speed_test '6746' 'India, Mumbai (SevenStar) ' 'http://speed2.7starnetworks.com'
  318. speed_test '23722' 'India, Bengaluru (DBroadband) ' 'http://speedtest.dbroadband.in'
  319. speed_test '1131' 'Sri Lanka, Colombo (Telecom PLC)' 'http://speedtest2.sltnet.lk'
  320. speed_test '21188' 'Pakistan, Islamabad (Jazz) ' 'http://speedtest-isb1.jazz.com.pk'
  321. speed_test '2802' 'Kazakhstan, Astana (KCell) ' 'http://ast-st-02.kcell.kz'
  322. speed_test '3212' 'Tajikistan, Dushanbe (Babilon-M)' 'http://ispeedtest.babilon-m.tj'
  323. speed_test '5792' 'Mongolia, Ulaanbaatar (Mobicom) ' 'http://coverage.mobicom.mn'
  324. speed_test '7147' 'Bangladesh, Dhaka (Skytel) ' 'http://speedtest2.skytelbd.com'
  325. speed_test '14901' 'Bhutan, Thimphu (Bhutan Telecom)' 'http://speedtest.bt.bt'
  326. speed_test '20882' 'Myanmar, Mandalay (Ooredoo) ' 'http://speedtest.ooredoo.com.mm'
  327. speed_test '26845' 'Laos, Vientaine (Mangkone) ' 'http://speedtest.mangkone.com'
  328. speed_test '4347' 'Thailand, Bangkok (CAT Telecom) ' 'http://www.catspeedtest.com'
  329. speed_test '12545' 'Cambodia, Phnom Penh (Smart) ' 'http://speedtest.smart.com.kh'
  330. speed_test '2552' 'Vietnam, Hanoi (FPT Telecom) ' 'http://speedtesthn.rad.fpt.net'
  331. speed_test '27261' 'Malaysia, Kuala Lumpur (Extreme)' 'http://kl-speedtest.ebb.my'
  332. speed_test '7556' 'Singapore (PT FirstMedia) ' 'http://sg-speedtest.link.net.id'
  333. speed_test '17516' 'Indonesia, Jakarta (Desnet) ' 'http://speedtest.desnet.id'
  334. speed_test '26048' 'Philippines, Manila (Sky Fiber) ' 'http://mnl-speedtest.globe.com.ph'
  335. speed_test '24375' 'Hong Kong (GTT) ' 'http://hon.speedtest.gtt.net'
  336. speed_test '13506' 'Taiwan, Taipei (TAIFO) ' 'http://speedtest.taifo.com.tw'
  337. speed_test '7139' 'Japan, Tsukuba (SoftEther) ' 'http://speedtest2.softether.co.jp'
  338.  
  339. #rm -rf speedtest.py
  340. }
  341.  
  342. print_speedtest_sa() {
  343. echo "" | tee -a $log
  344. echostyle "## South America Speedtest"
  345. echo "" | tee -a $log
  346. printf "%-38s%-17s%-16s%-7s\n" " Location" "Upload" "Download" "Ping" | tee -a $log
  347. printf "%-75s\n" "-" | sed 's/\s/-/g' | tee -a $log
  348. speed_test '' 'Speedtest.net '
  349. speed_test '9948' 'Brazil, Sao Paulo (Vogel Telecom) ' 'http://speedtestsp1.stech.net.br'
  350. speed_test '18890' 'Brazil, Fortaleza (Claro) ' 'http://spd1.claro.com.br'
  351. speed_test '11683' 'Colombia, Bogota (Level 3) ' 'http://speedtest.globalcrossing.com.co'
  352. speed_test '10511' 'Ecuador, Quito (Iplanet) ' 'http://sp1.iplanet.ec'
  353. speed_test '5272' 'Peru, Lima (Fiberluxperu) ' 'http://medidor.fiberluxperu.com'
  354. speed_test '27563' 'Bolivia, La Paz (Sirio) ' 'http://speedtest.sirio.com.bo'
  355. speed_test '2830' 'Paraguay, Asuncion (Personal) ' 'http://speedtest1.personal.com.py'
  356. speed_test '24622' 'Chile, Santiago (Netglobalis) ' 'http://speedtest.netglobalis.net'
  357. speed_test '6825' 'Argentina, Buenos Aires (Telefonica)' 'http://speedtest2.gics.telefonica.com.ar'
  358. speed_test '1546' 'Uruguay, Montevideo (Antel) ' 'http://speedtest.movistar.com.uy'
  359.  
  360. #rm -rf speedtest.py
  361. }
  362.  
  363. print_speedtest_ukraine() {
  364. echo "" | tee -a $log
  365. echostyle "## Ukraine Speedtest"
  366. echo "" | tee -a $log
  367. printf "%-32s%-17s%-17s%-7s\n" " Location" "Upload" "Download" "Ping" | tee -a $log
  368. printf "%-75s\n" "-" | sed 's/\s/-/g' | tee -a $log
  369. speed_test '' 'Speedtest.net '
  370. speed_test '6446' 'Ukraine, Kyiv (KyivStar) ' 'http://www.speedtest2.kyivstar.ua'
  371. speed_test '2518' 'Ukraine, Kyiv (Volia) ' 'http://speedtest2.volia.com'
  372. speed_test '14887' 'Ukraine, Lviv (UARNet) ' 'http://speedtest.uar.net'
  373. speed_test '3022' 'Ukraine, Uzhgorod (TransCom) ' 'http://speedtest.tcom.uz.ua'
  374. speed_test '19332' 'Ukraine, Chernivtsi (C.T.Net) ' 'http://speedtest.ctn.cv.ua'
  375. speed_test '3861' 'Ukraine, Zhytomyr (DKS) ' 'http://speedtest1.dks.com.ua'
  376. speed_test '8633' 'Ukraine, Cherkasy (McLaut) ' 'http://speedtest2.mclaut.com'
  377. speed_test '2970' 'Ukraine, Kharkiv (OnLine) ' 'http://speedtest.isp.kh.ua'
  378. speed_test '23620' 'Ukraine, Dnipro (Fregat) ' 'http://test.fregat.net'
  379. speed_test '2796' 'Ukraine, Odesa (Black Sea) ' 'http://speedtest.blacksea.net.ua'
  380. speed_test '26725' 'Ukraine, Mariupol (CityLine) ' 'http://speedtest.cl.dn.ua'
  381.  
  382. #rm -rf speedtest.py
  383. }
  384.  
  385. print_speedtest_lviv() {
  386. echo "" | tee -a $log
  387. echostyle "## Lviv Speedtest"
  388. echo "" | tee -a $log
  389. printf "%-26s%-17s%-17s%-7s\n" " Location" "Upload" "Download" "Ping" | tee -a $log
  390. printf "%-75s\n" "-" | sed 's/\s/-/g' | tee -a $log
  391. speed_test '' 'Speedtest.net '
  392. speed_test '14887' 'Ukraine, Lviv (UARNet) ' 'http://speedtest.uar.net'
  393. speed_test '2445' 'Ukraine, Lviv (KOMiTEX) ' 'http://speedtest.komitex.net'
  394. speed_test '12786' 'Ukraine, Lviv (ASTRA) ' 'http://speedtest.astra.in.ua'
  395. speed_test '17398' 'Ukraine, Lviv (Kopiyka) ' 'http://speedtest.kopiyka.org'
  396. speed_test '6225' 'Ukraine, Lviv (ZNet) ' 'http://178.212.102.70'
  397. speed_test '1204' 'Ukraine, Lviv (Network) ' 'http://speedtest.network.lviv.ua'
  398. speed_test '21900' 'Ukraine, Lviv (LimNet) ' 'http://speedtest.limnet.com.ua'
  399.  
  400. #rm -rf speedtest.py
  401. }
  402.  
  403. print_speedtest_meast() {
  404. echo "" | tee -a $log
  405. echostyle "## Middle East Speedtest"
  406. echo "" | tee -a $log
  407. printf "%-30s%-17s%-17s%-7s\n" " Location" "Upload" "Download" "Ping" | tee -a $log
  408. printf "%-75s\n" "-" | sed 's/\s/-/g' | tee -a $log
  409. speed_test '' 'Speedtest.net '
  410. speed_test '16595' 'Cyprus, Larnaca (skywisp) ' 'http://speedtest1.skywisp.com.cy'
  411. speed_test '2434' 'Israel, Haifa (013Netvision)' 'http://speed2.013.net'
  412. speed_test '1689' 'Egypt, Cairo (Vodafone) ' 'http://speedtest.vodafone.com.eg'
  413. speed_test '12498' 'Lebanon, Tripoli (BItarNet) ' 'http://speedtest.bitarnet.net'
  414. speed_test '17398' 'UAE, Dubai (Orixcom) ' 'http://speedtest.orixcom.net'
  415. speed_test '14888' 'Qatar, Doha (Vodafone) ' 'http://speedtest01.vodafone.com.qa'
  416. speed_test '608' 'SA, Riyadh (Saudi Telecom) ' 'http://speedtest.saudi.net.sa'
  417. speed_test '17574' 'Bahrain, Manama (Zain) ' 'http://speedtest.saudi.net.sa'
  418. speed_test '13583' 'Iran, Tehran (Fanap Telecom)' 'http://speedtest.fanaptelecom.ir'
  419.  
  420. #rm -rf speedtest.py
  421. }
  422.  
  423. print_speedtest_ru() {
  424. echo "" | tee -a $log
  425. echostyle "## Russian Federation Speedtest"
  426. echo "" | tee -a $log
  427. printf "%-36s%-17s%-17s%-7s\n" " Location" "Upload" "Download" "Ping" | tee -a $log
  428. printf "%-75s\n" "-" | sed 's/\s/-/g' | tee -a $log
  429. speed_test '' 'Speedtest.net '
  430. speed_test '1907' 'Russia, Moscow (MTS) ' 'http://librarian.comstar.ru'
  431. speed_test '10987' 'Russia, Moscow (Beeline) ' 'http://librarian.comstar.ru'
  432. speed_test '6562' 'Russia, Moscow (Tele2) ' 'http://176.59.63.150'
  433. speed_test '2599' 'Russia, St.Petersburg (Rostelecom)' 'http://sankt-peterburg2.speedtest.rt.ru'
  434. speed_test '4231' 'Russia, St.Petersburg (Prometey) ' 'http://speedtest1.ptspb.net'
  435. speed_test '1497' 'Russia, Voronezh (Kvant-Telecom) ' 'http://speedtest.kvant-telecom.ru'
  436. speed_test '5623' 'Russia, Krasnodar (Beeline) ' 'http://krr1.speedtest.corbina.net'
  437. speed_test '26823' 'Russia, Volgograd (Beeline) ' 'http://volgograd-speedtest.corbina.net'
  438. speed_test '3256' 'Russia, Samara (TTK) ' 'http://test.samara-ttk.ru'
  439. speed_test '4503' 'Russia, Nizhny Novgorod (MTS) ' 'http://speedtest.nnov.mts.ru'
  440. speed_test '1930' 'Russia, Ekaterinburg (Ural WES) ' 'http://tarvalon.ural.net'
  441. speed_test '5127' 'Russia, Omsk (Beeline) ' 'http://omsk2.speedtest.corbina.net'
  442. speed_test '2313' 'Russia, Surgut (METROSET) ' 'http://speedtest.sg.metro-set.ru'
  443. speed_test '6430' 'Russia, Novosibirsk (Tele2) ' 'http://176.59.159.158'
  444. speed_test '4541' 'Russia, Irkutsk (TransTeleCom) ' 'http://5.254.224.9'
  445. speed_test '5647' 'Russia, Yakutsk (MegaFon) ' 'http://ykt.speedtest-dvf.megafon.ru'
  446. speed_test '25204' 'Russia, Vladivostok (Rostelecom) ' 'http://speedtest.inetvl.ru'
  447.  
  448. #rm -rf speedtest.py
  449. }
  450.  
  451. geekbench4() {
  452. echo "" | tee -a $log
  453. echo -e " Performing Geekbench v4 CPU Benchmark test. Please wait..."
  454.  
  455. GEEKBENCH_PATH=$HOME/geekbench
  456. mkdir -p $GEEKBENCH_PATH
  457. curl -s http://cdn.geekbench.com/Geekbench-4.3.4-Linux.tar.gz | tar xz --strip-components=1 -C $GEEKBENCH_PATH
  458. GEEKBENCH_TEST=$($GEEKBENCH_PATH/geekbench4 | grep "https://browser")
  459. GEEKBENCH_URL=$(echo -e $GEEKBENCH_TEST | head -1)
  460. GEEKBENCH_URL_CLAIM=$(echo $GEEKBENCH_URL | awk '{ print $2 }')
  461. GEEKBENCH_URL=$(echo $GEEKBENCH_URL | awk '{ print $1 }')
  462. sleep 10
  463. GEEKBENCH_SCORES=$(curl -s $GEEKBENCH_URL | grep "class='score' rowspan")
  464. GEEKBENCH_SCORES_SINGLE=$(echo $GEEKBENCH_SCORES | awk -v FS="(>|<)" '{ print $3 }')
  465. GEEKBENCH_SCORES_MULTI=$(echo $GEEKBENCH_SCORES | awk -v FS="(<|>)" '{ print $7 }')
  466.  
  467. if [[ $GEEKBENCH_SCORES_SINGLE -le 1700 ]]; then
  468. grank="(POOR)"
  469. elif [[ $GEEKBENCH_SCORES_SINGLE -ge 1700 && $GEEKBENCH_SCORES_SINGLE -le 2300 ]]; then
  470. grank="(FAIR)"
  471. elif [[ $GEEKBENCH_SCORES_SINGLE -ge 2300 && $GEEKBENCH_SCORES_SINGLE -le 3000 ]]; then
  472. grank="(GOOD)"
  473. elif [[ $GEEKBENCH_SCORES_SINGLE -ge 3000 && $GEEKBENCH_SCORES_SINGLE -le 4000 ]]; then
  474. grank="(VERY GOOD)"
  475. else
  476. grank="(EXCELLENT)"
  477. fi
  478.  
  479. echo -ne "\e[1A"; echo -ne "\033[0K\r"
  480. echostyle "## Geekbench v4 CPU Benchmark:"
  481. echo "" | tee -a $log
  482. echo -e " Single Core : $GEEKBENCH_SCORES_SINGLE $grank" | tee -a $log
  483. echo -e " Multi Core : $GEEKBENCH_SCORES_MULTI" | tee -a $log
  484. [ ! -z "$GEEKBENCH_URL_CLAIM" ] && echo -e "$GEEKBENCH_URL_CLAIM" > geekbench4_claim.url 2> /dev/null
  485. echo "" | tee -a $log
  486. echo -e " Cooling down..."
  487. sleep 9
  488. echo -ne "\e[1A"; echo -ne "\033[0K\r"
  489. echo -e " Ready to continue..."
  490. sleep 3
  491. echo -ne "\e[1A"; echo -ne "\033[0K\r"
  492. }
  493.  
  494. calc_disk() {
  495. local total_size=0
  496. local array=$@
  497. for size in ${array[@]}
  498. do
  499. [ "${size}" == "0" ] && size_t=0 || size_t=`echo ${size:0:${#size}-1}`
  500. [ "`echo ${size:(-1)}`" == "K" ] && size=0
  501. [ "`echo ${size:(-1)}`" == "M" ] && size=$( awk 'BEGIN{printf "%.1f", '$size_t' / 1024}' )
  502. [ "`echo ${size:(-1)}`" == "T" ] && size=$( awk 'BEGIN{printf "%.1f", '$size_t' * 1024}' )
  503. [ "`echo ${size:(-1)}`" == "G" ] && size=${size_t}
  504. total_size=$( awk 'BEGIN{printf "%.1f", '$total_size' + '$size'}' )
  505. done
  506. echo ${total_size}
  507. }
  508.  
  509. power_time() {
  510.  
  511. 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"
  512. }
  513.  
  514. install_smart() {
  515. # install smartctl
  516. if [ ! -e '/usr/sbin/smartctl' ]; then
  517. echo "Installing Smartctl ..."
  518. if [ "${release}" == "centos" ]; then
  519. yum update > /dev/null 2>&1
  520. yum -y install smartmontools > /dev/null 2>&1
  521. else
  522. apt-get update > /dev/null 2>&1
  523. apt-get -y install smartmontools > /dev/null 2>&1
  524. fi
  525. fi
  526. }
  527.  
  528. ip_info(){
  529. # use jq tool
  530. result=$(curl -s 'http://ip-api.com/json')
  531. country=$(echo $result | jq '.country' | sed 's/\"//g')
  532. city=$(echo $result | jq '.city' | sed 's/\"//g')
  533. isp=$(echo $result | jq '.isp' | sed 's/\"//g')
  534. as_tmp=$(echo $result | jq '.as' | sed 's/\"//g')
  535. asn=$(echo $as_tmp | awk -F ' ' '{print $1}')
  536. org=$(echo $result | jq '.org' | sed 's/\"//g')
  537. countryCode=$(echo $result | jq '.countryCode' | sed 's/\"//g')
  538. region=$(echo $result | jq '.regionName' | sed 's/\"//g')
  539. if [ -z "$city" ]; then
  540. city=${region}
  541. fi
  542.  
  543. echo -e " ASN & ISP : $asn, $isp" | tee -a $log
  544. echo -e " Organization : $org" | tee -a $log
  545. echo -e " Location : $city, $country / $countryCode" | tee -a $log
  546. echo -e " Region : $region" | tee -a $log
  547. }
  548.  
  549. ip_info2(){
  550. # no jq
  551. country=$(curl -s https://ipapi.co/country_name/)
  552. city=$(curl -s https://ipapi.co/city/)
  553. asn=$(curl -s https://ipapi.co/asn/)
  554. org=$(curl -s https://ipapi.co/org/)
  555. countryCode=$(curl -s https://ipapi.co/country/)
  556. region=$(curl -s https://ipapi.co/region/)
  557.  
  558. echo -e " ASN & ISP : $asn" | tee -a $log
  559. echo -e " Organization : $org" | tee -a $log
  560. echo -e " Location : $city, $country / $countryCode" | tee -a $log
  561. echo -e " Region : $region" | tee -a $log
  562. }
  563.  
  564. ip_info3(){
  565. # use python tool
  566. country=$(python ip_info.py country)
  567. city=$(python ip_info.py city)
  568. isp=$(python ip_info.py isp)
  569. as_tmp=$(python ip_info.py as)
  570. asn=$(echo $as_tmp | awk -F ' ' '{print $1}')
  571. org=$(python ip_info.py org)
  572. countryCode=$(python ip_info.py countryCode)
  573. region=$(python ip_info.py regionName)
  574.  
  575. echo -e " ASN & ISP : $asn, $isp" | tee -a $log
  576. echo -e " Organization : $org" | tee -a $log
  577. echo -e " Location : $city, $country / $countryCode" | tee -a $log
  578. echo -e " Region : $region" | tee -a $log
  579.  
  580. #rm -rf ip_info.py
  581. }
  582.  
  583. ip_info4(){
  584. ip_date=$(curl -4 -s http://api.ip.la/en?json)
  585. echo $ip_date > ip_json.json
  586. isp=$(python tools.py geoip isp)
  587. as_tmp=$(python tools.py geoip as)
  588. asn=$(echo $as_tmp | awk -F ' ' '{print $1}')
  589. org=$(python tools.py geoip org)
  590. if [ -z "ip_date" ]; then
  591. echo $ip_date
  592. echo "hala"
  593. country=$(python tools.py ipip country_name)
  594. city=$(python tools.py ipip city)
  595. countryCode=$(python tools.py ipip country_code)
  596. region=$(python tools.py ipip province)
  597. else
  598. country=$(python tools.py geoip country)
  599. city=$(python tools.py geoip city)
  600. countryCode=$(python tools.py geoip countryCode)
  601. region=$(python tools.py geoip regionName)
  602. fi
  603. if [ -z "$city" ]; then
  604. city=${region}
  605. fi
  606.  
  607. echo -e " ASN & ISP : $asn, $isp" | tee -a $log
  608. echo -e " Organization : $org" | tee -a $log
  609. echo -e " Location : $city, $country / $countryCode" | tee -a $log
  610. echo -e " Region : $region" | tee -a $log
  611.  
  612. #rm -rf tools.py
  613. #rm -rf ip_json.json
  614. }
  615.  
  616. virt_check(){
  617. if hash ifconfig 2>/dev/null; then
  618. eth=$(ifconfig)
  619. fi
  620.  
  621. virtualx=$(dmesg) 2>/dev/null
  622.  
  623. if grep docker /proc/1/cgroup -qa; then
  624. virtual="Docker"
  625. elif grep lxc /proc/1/cgroup -qa; then
  626. virtual="Lxc"
  627. elif grep -qa container=lxc /proc/1/environ; then
  628. virtual="Lxc"
  629. elif [[ -f /proc/user_beancounters ]]; then
  630. virtual="OpenVZ"
  631. elif [[ "$virtualx" == *kvm-clock* ]]; then
  632. virtual="KVM"
  633. elif [[ "$cname" == *KVM* ]]; then
  634. virtual="KVM"
  635. elif [[ "$virtualx" == *"VMware Virtual Platform"* ]]; then
  636. virtual="VMware"
  637. elif [[ "$virtualx" == *"Parallels Software International"* ]]; then
  638. virtual="Parallels"
  639. elif [[ "$virtualx" == *VirtualBox* ]]; then
  640. virtual="VirtualBox"
  641. elif [[ -e /proc/xen ]]; then
  642. virtual="Xen"
  643. elif [[ "$sys_manu" == *"Microsoft Corporation"* ]]; then
  644. if [[ "$sys_product" == *"Virtual Machine"* ]]; then
  645. if [[ "$sys_ver" == *"7.0"* || "$sys_ver" == *"Hyper-V" ]]; then
  646. virtual="Hyper-V"
  647. else
  648. virtual="Microsoft Virtual Machine"
  649. fi
  650. fi
  651. else
  652. virtual="Dedicated"
  653. fi
  654. }
  655.  
  656. power_time_check(){
  657. echo -ne " Power time of disk : "
  658. install_smart
  659. ptime=$(power_time)
  660. echo -e "$ptime Hours"
  661. }
  662.  
  663. freedisk() {
  664. # check free space
  665. #spacename=$( df -m . | awk 'NR==2 {print $1}' )
  666. #spacenamelength=$(echo ${spacename} | awk '{print length($0)}')
  667. #if [[ $spacenamelength -gt 20 ]]; then
  668. # freespace=$( df -m . | awk 'NR==3 {print $3}' )
  669. #else
  670. # freespace=$( df -m . | awk 'NR==2 {print $4}' )
  671. #fi
  672. freespace=$( df -m . | awk 'NR==2 {print $4}' )
  673. if [[ $freespace == "" ]]; then
  674. $freespace=$( df -m . | awk 'NR==3 {print $3}' )
  675. fi
  676. if [[ $freespace -gt 1024 ]]; then
  677. printf "%s" $((1024*2))
  678. elif [[ $freespace -gt 512 ]]; then
  679. printf "%s" $((512*2))
  680. elif [[ $freespace -gt 256 ]]; then
  681. printf "%s" $((256*2))
  682. elif [[ $freespace -gt 128 ]]; then
  683. printf "%s" $((128*2))
  684. else
  685. printf "1"
  686. fi
  687. }
  688.  
  689. print_system_info() {
  690. echo -e " OS : $opsy ($lbit Bit)" | tee -a $log
  691. echo -e " Virt/Kernel : $virtual / $kern" | tee -a $log
  692. echo -e " CPU Model : $cname" | tee -a $log
  693. echo -e " CPU Cores : $cores @ $freq MHz $arch $corescache Cache" | tee -a $log
  694. echo -e " CPU Flags : $cpu_aes & $cpu_virt" | tee -a $log
  695. echo -e " Load Average : $load" | tee -a $log
  696. echo -e " Total Space : $hdd ($hddused ~$hddfree used)" | tee -a $log
  697. echo -e " Total RAM : $uram MB / $tram MB ($bram MB Buff)" | tee -a $log
  698. echo -e " Total SWAP : $uswap MB / $swap MB" | tee -a $log
  699. echo -e " Uptime : $up" | tee -a $log
  700. #echo -e " TCP CC : $tcpctrl" | tee -a $log
  701. printf "%-75s\n" "-" | sed 's/\s/-/g' | tee -a $log
  702. }
  703.  
  704. get_system_info() {
  705. cname=$( awk -F: '/model name/ {name=$2} END {print name}' /proc/cpuinfo | sed 's/^[ \t]*//;s/[ \t]*$//' )
  706. cores=$( awk -F: '/model name/ {core++} END {print core}' /proc/cpuinfo )
  707. freq=$( awk -F: '/cpu MHz/ {freq=$2} END {print freq}' /proc/cpuinfo | sed 's/^[ \t]*//;s/[ \t]*$//' )
  708. corescache=$( awk -F: '/cache size/ {cache=$2} END {print cache}' /proc/cpuinfo | sed 's/^[ \t]*//;s/[ \t]*$//' )
  709. cpu_aes=$(cat /proc/cpuinfo | grep aes)
  710. [[ -z "$cpu_aes" ]] && cpu_aes="AES-NI Disabled" || cpu_aes="AES-NI Enabled"
  711. cpu_virt=$(cat /proc/cpuinfo | grep 'vmx\|svm')
  712. [[ -z "$cpu_virt" ]] && cpu_virt="VM-x/AMD-V Disabled" || cpu_virt="VM-x/AMD-V Enabled"
  713. tram=$( free -m | awk '/Mem/ {print $2}' )
  714. uram=$( free -m | awk '/Mem/ {print $3}' )
  715. bram=$( free -m | awk '/Mem/ {print $6}' )
  716. swap=$( free -m | awk '/Swap/ {print $2}' )
  717. uswap=$( free -m | awk '/Swap/ {print $3}' )
  718. up=$( awk '{a=$1/86400;b=($1%86400)/3600;c=($1%3600)/60} {printf("%d days %d:%d\n",a,b,c)}' /proc/uptime )
  719. load=$( w | head -1 | awk -F'load average:' '{print $2}' | sed 's/^[ \t]*//;s/[ \t]*$//' )
  720. opsy=$( get_opsy )
  721. arch=$( uname -m )
  722. lbit=$( getconf LONG_BIT )
  723. kern=$( uname -r )
  724. #ipv6=$( wget -qO- -t1 -T2 ipv6.icanhazip.com )
  725. #disk_size1=($( LANG=C df -hPl | grep -wvE '\-|none|tmpfs|overlay|shm|udev|devtmpfs|by-uuid|chroot|Filesystem' | awk '{print $2}' ))
  726. #disk_size2=($( LANG=C df -hPl | grep -wvE '\-|none|tmpfs|overlay|shm|udev|devtmpfs|by-uuid|chroot|Filesystem' | awk '{print $3}' ))
  727. #disk_total_size=$( calc_disk ${disk_size1[@]} )
  728. #disk_used_size=$( calc_disk ${disk_size2[@]} )
  729. hdd=$(df -t simfs -t ext2 -t ext3 -t ext4 -t btrfs -t xfs -t vfat -t ntfs -t swap --total -h | grep total | awk '{ print $2 }')
  730. hddused=$(df -t simfs -t ext2 -t ext3 -t ext4 -t btrfs -t xfs -t vfat -t ntfs -t swap --total -h | grep total | awk '{ print $3 }')
  731. hddfree=$(df -t simfs -t ext2 -t ext3 -t ext4 -t btrfs -t xfs -t vfat -t ntfs -t swap --total -h | grep total | awk '{ print $5 }')
  732. #tcp congestion control
  733. #tcpctrl=$( sysctl net.ipv4.tcp_congestion_control | awk -F ' ' '{print $3}' )
  734.  
  735. #tmp=$(python tools.py disk 0)
  736. #disk_total_size=$(echo $tmp | sed s/G//)
  737. #tmp=$(python tools.py disk 1)
  738. #disk_used_size=$(echo $tmp | sed s/G//)
  739.  
  740. virt_check
  741. }
  742.  
  743. write_test() {
  744. (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]*$//'
  745. }
  746.  
  747. averageio() {
  748. ioraw1=$( echo $1 | awk 'NR==1 {print $1}' )
  749. [ "$(echo $1 | awk 'NR==1 {print $2}')" == "GB/s" ] && ioraw1=$( awk 'BEGIN{print '$ioraw1' * 1024}' )
  750. ioraw2=$( echo $2 | awk 'NR==1 {print $1}' )
  751. [ "$(echo $2 | awk 'NR==1 {print $2}')" == "GB/s" ] && ioraw2=$( awk 'BEGIN{print '$ioraw2' * 1024}' )
  752. ioraw3=$( echo $3 | awk 'NR==1 {print $1}' )
  753. [ "$(echo $3 | awk 'NR==1 {print $2}')" == "GB/s" ] && ioraw3=$( awk 'BEGIN{print '$ioraw3' * 1024}' )
  754. ioall=$( awk 'BEGIN{print '$ioraw1' + '$ioraw2' + '$ioraw3'}' )
  755. ioavg=$( awk 'BEGIN{printf "%.1f", '$ioall' / 3}' )
  756. printf "%s" "$ioavg"
  757. }
  758.  
  759. cpubench() {
  760. if hash $1 2>$NULL; then
  761. io=$( ( dd if=/dev/zero bs=512K count=$2 | $1 ) 2>&1 | grep 'copied' | awk -F, '{io=$NF} END {print io}' )
  762. if [[ $io != *"."* ]]; then
  763. printf "%4i %s" "${io% *}" "${io##* }"
  764. else
  765. printf "%4i.%s" "${io%.*}" "${io#*.}"
  766. fi
  767. else
  768. printf " %s not found on system." "$1"
  769. fi
  770. }
  771.  
  772. iotest() {
  773. echostyle "## IO Test"
  774. echo "" | tee -a $log
  775.  
  776. # start testing
  777. writemb=$(freedisk)
  778. if [[ $writemb -gt 512 ]]; then
  779. writemb_size="$(( writemb / 2 / 2 ))MB"
  780. writemb_cpu="$(( writemb / 2 ))"
  781. else
  782. writemb_size="$writemb"MB
  783. writemb_cpu=$writemb
  784. fi
  785.  
  786. # CPU Speed test
  787. echostyle "CPU Speed:"
  788. echo " bzip2 :$( cpubench bzip2 $writemb_cpu )" | tee -a $log
  789. echo " sha256 :$( cpubench sha256sum $writemb_cpu )" | tee -a $log
  790. echo " md5sum :$( cpubench md5sum $writemb_cpu )" | tee -a $log
  791. echo "" | tee -a $log
  792.  
  793. # RAM Speed test
  794. # set ram allocation for mount
  795. tram_mb="$( free -m | grep Mem | awk 'NR=1 {print $2}' )"
  796. if [[ tram_mb -gt 1900 ]]; then
  797. sbram=1024M
  798. sbcount=2048
  799. else
  800. sbram=$(( tram_mb / 2 ))M
  801. sbcount=$tram_mb
  802. fi
  803. [[ -d $benchram ]] || mkdir $benchram
  804. mount -t tmpfs -o size=$sbram tmpfs $benchram/
  805. echostyle "RAM Speed:"
  806. iow1=$( ( dd if=/dev/zero of=$benchram/zero bs=512K count=$sbcount ) 2>&1 | awk -F, '{io=$NF} END { print io}' )
  807. ior1=$( ( dd if=$benchram/zero of=$NULL bs=512K count=$sbcount; rm -f test ) 2>&1 | awk -F, '{io=$NF} END { print io}' )
  808. iow2=$( ( dd if=/dev/zero of=$benchram/zero bs=512K count=$sbcount ) 2>&1 | awk -F, '{io=$NF} END { print io}' )
  809. ior2=$( ( dd if=$benchram/zero of=$NULL bs=512K count=$sbcount; rm -f test ) 2>&1 | awk -F, '{io=$NF} END { print io}' )
  810. iow3=$( ( dd if=/dev/zero of=$benchram/zero bs=512K count=$sbcount ) 2>&1 | awk -F, '{io=$NF} END { print io}' )
  811. ior3=$( ( dd if=$benchram/zero of=$NULL bs=512K count=$sbcount; rm -f test ) 2>&1 | awk -F, '{io=$NF} END { print io}' )
  812. echo " Avg. write : $(averageio "$iow1" "$iow2" "$iow3") MB/s" | tee -a $log
  813. echo " Avg. read : $(averageio "$ior1" "$ior2" "$ior3") MB/s" | tee -a $log
  814. rm $benchram/zero
  815. umount $benchram
  816. rm -rf $benchram
  817. echo "" | tee -a $log
  818.  
  819. # Disk test
  820. #echostyle "Disk Speed:"
  821. #if [[ $writemb != "1" ]]; then
  822. # io=$( ( dd bs=512K count=$writemb if=/dev/zero of=test; rm -f test ) 2>&1 | awk -F, '{io=$NF} END { print io}' )
  823. # echo " I/O Speed :$io" | tee -a $log
  824.  
  825. # io=$( ( dd bs=512K count=$writemb if=/dev/zero of=test oflag=direct; rm -f test ) 2>&1 | awk -F, '{io=$NF} END { print io}' )
  826. # echo " I/O Direct :$io" | tee -a $log
  827. #else
  828. # echo " Not enough space to test." | tee -a $log
  829. #fi
  830. #echo "" | tee -a $log
  831. }
  832.  
  833.  
  834. write_io() {
  835. writemb=$(freedisk)
  836. writemb_size="$(( writemb / 2 ))MB"
  837. if [[ $writemb_size == "1024MB" ]]; then
  838. writemb_size="1.0GB"
  839. fi
  840.  
  841. if [[ $writemb != "1" ]]; then
  842. echostyle "Disk Write Speed:"
  843. echo -n " 1st run : " | tee -a $log
  844. io1=$( write_test $writemb )
  845. echo -e "$io1" | tee -a $log
  846. echo -n " 2dn run : " | tee -a $log
  847. io2=$( write_test $writemb )
  848. echo -e "$io2" | tee -a $log
  849. echo -n " 3rd run : " | tee -a $log
  850. io3=$( write_test $writemb )
  851. echo -e "$io3" | tee -a $log
  852. ioraw1=$( echo $io1 | awk 'NR==1 {print $1}' )
  853. [ "`echo $io1 | awk 'NR==1 {print $2}'`" == "GB/s" ] && ioraw1=$( awk 'BEGIN{print '$ioraw1' * 1024}' )
  854. ioraw2=$( echo $io2 | awk 'NR==1 {print $1}' )
  855. [ "`echo $io2 | awk 'NR==1 {print $2}'`" == "GB/s" ] && ioraw2=$( awk 'BEGIN{print '$ioraw2' * 1024}' )
  856. ioraw3=$( echo $io3 | awk 'NR==1 {print $1}' )
  857. [ "`echo $io3 | awk 'NR==1 {print $2}'`" == "GB/s" ] && ioraw3=$( awk 'BEGIN{print '$ioraw3' * 1024}' )
  858. ioall=$( awk 'BEGIN{print '$ioraw1' + '$ioraw2' + '$ioraw3'}' )
  859. ioavg=$( awk 'BEGIN{printf "%.1f", '$ioall' / 3}' )
  860. echo -e " -----------------------" | tee -a $log
  861. echo -e " Average : $ioavg MB/s" | tee -a $log
  862. else
  863. echo -e " Not enough space!"
  864. fi
  865. }
  866.  
  867. # https://github.com/masonr/yet-another-bench-script
  868. function disk_test () {
  869. I=0
  870. DISK_WRITE_TEST_RES=()
  871. DISK_READ_TEST_RES=()
  872. DISK_WRITE_TEST_AVG=0
  873. DISK_READ_TEST_AVG=0
  874. DATE=`date -Iseconds | sed -e "s/:/_/g"`
  875. OS=$(awk -F= '/^NAME/{print $2}' /etc/os-release)
  876. while [ $I -lt 3 ]
  877. do
  878. DISK_WRITE_TEST=$(dd if=/dev/zero of=$DISK_PATH/$DATE.test bs=64k count=16k oflag=direct |& grep copied | awk '{ print $(NF-1) " " $(NF)}')
  879. VAL=$(echo $DISK_WRITE_TEST | cut -d " " -f 1)
  880. [[ "$DISK_WRITE_TEST" == *"GB"* ]] && VAL=$(awk -v a="$VAL" 'BEGIN { print a * 1000 }')
  881. DISK_WRITE_TEST_RES+=( "$VAL" )
  882. DISK_WRITE_TEST_AVG=$(awk -v a="$DISK_WRITE_TEST_AVG" -v b="$VAL" 'BEGIN { print a + b }')
  883.  
  884. DISK_READ_TEST=$($DISK_PATH/ioping -R -L -D -B -w 6 . | awk '{ print $4 / 1000 / 1000 }')
  885. DISK_READ_TEST_RES+=( "$DISK_READ_TEST" )
  886. DISK_READ_TEST_AVG=$(awk -v a="$DISK_READ_TEST_AVG" -v b="$DISK_READ_TEST" 'BEGIN { print a + b }')
  887.  
  888. I=$(( $I + 1 ))
  889. done
  890. DISK_WRITE_TEST_AVG=$(awk -v a="$DISK_WRITE_TEST_AVG" 'BEGIN { print a / 3 }')
  891. DISK_READ_TEST_AVG=$(awk -v a="$DISK_READ_TEST_AVG" 'BEGIN { print a / 3 }')
  892. }
  893.  
  894. ioping() {
  895. echo -e "Performing disk performance test. This may take a couple minutes to complete..."
  896.  
  897. DISK_PATH=$HOME/disk
  898. mkdir -p $DISK_PATH
  899. curl -s https://raw.githubusercontent.com/masonr/yet-another-bench-script/master/ioping -o $DISK_PATH/ioping
  900. chmod +x $DISK_PATH/ioping
  901.  
  902. disk_test
  903.  
  904. if [ $(echo $DISK_WRITE_TEST_AVG | cut -d "." -f 1) -ge 1000 ]; then
  905. DISK_WRITE_TEST_AVG=$(awk -v a="$DISK_WRITE_TEST_AVG" 'BEGIN { print a / 1000 }')
  906. DISK_WRITE_TEST_UNIT="GB/s"
  907. else
  908. DISK_WRITE_TEST_UNIT="MB/s"
  909. fi
  910. if [ $(echo $DISK_READ_TEST_AVG | cut -d "." -f 1) -ge 1000 ]; then
  911. DISK_READ_TEST_AVG=$(awk -v a="$DISK_READ_TEST_AVG" 'BEGIN { print a / 1000 }')
  912. DISK_READ_TEST_UNIT="GB/s"
  913. else
  914. DISK_READ_TEST_UNIT="MB/s"
  915. fi
  916.  
  917. echo -ne "\e[1A"; echo -ne "\033[0K\r"
  918. echostyle "Disk Write Speed:" | tee -a $log
  919. echo -e "" | tee -a $log
  920. echo -e " 1st run : ${DISK_WRITE_TEST_RES[0]} MB/s" | tee -a $log
  921. echo -e " 2dn run : ${DISK_WRITE_TEST_RES[1]} MB/s" | tee -a $log
  922. echo -e " 3rd run : ${DISK_WRITE_TEST_RES[2]} MB/s" | tee -a $log
  923. echo -e " -----------------------" | tee -a $log
  924. echo -e " Average : ${DISK_WRITE_TEST_AVG} ${DISK_WRITE_TEST_UNIT}" | tee -a $log
  925. echo -e "" | tee -a $log
  926. echostyle "Disk Read Speed:" | tee -a $log
  927. echo -e "" | tee -a $log
  928. echo -e " 1st run : ${DISK_READ_TEST_RES[0]} MB/s" | tee -a $log
  929. echo -e " 2dn run : ${DISK_READ_TEST_RES[1]} MB/s" | tee -a $log
  930. echo -e " 3rd run : ${DISK_READ_TEST_RES[2]} MB/s" | tee -a $log
  931. echo -e " -----------------------" | tee -a $log
  932. echo -e " Average : ${DISK_READ_TEST_AVG} ${DISK_READ_TEST_UNIT}" | tee -a $log
  933. echo -e "" | tee -a $log
  934. rm -rf $DISK_PATH;
  935. #rm -f speedtest.sh
  936. }
  937.  
  938. print_end_time() {
  939. echo "" | tee -a $log
  940. end=$(date +%s)
  941. time=$(( $end - $start ))
  942. if [[ $time -gt 60 ]]; then
  943. min=$(expr $time / 60)
  944. sec=$(expr $time % 60)
  945. echo -ne " Finished in : ${min} min ${sec} sec"
  946. else
  947. echo -ne " Finished in : ${time} sec"
  948. fi
  949. #echo -ne "\n Current time : "
  950. #echo $(date +%Y-%m-%d" "%H:%M:%S)
  951. printf '\n'
  952. utc_time=$(date -u '+%F %T')
  953. echo " Timestamp : $utc_time UTC" | tee -a $log
  954. #echo " Finished!"
  955. echo " Saved in : $log"
  956. echo "" | tee -a $log
  957. }
  958.  
  959. print_intro() {
  960. printf "%-75s\n" "-" | sed 's/\s/-/g'
  961. printf ' Speedtest Monster v.1.4.5 2019-10-13 \n' | tee -a $log
  962. printf " Region: %s https://bench.monster/speedtest.html\n" $region_name | tee -a $log
  963. printf " Usage : curl -LsO bench.monster/speedtest.sh; bash speedtest.sh -%s\n" $region_name | tee -a $log
  964. echo "" | tee -a $log
  965. }
  966.  
  967. sharetest() {
  968. echo " Share results:"
  969. echo " - $result_speed"
  970. log_preupload
  971. case $1 in
  972. 'ubuntu')
  973. share_link=$( curl -v --data-urlencode "content@$log_up" -d "poster=speedtest.sh" -d "syntax=text" "https://paste.ubuntu.com" 2>&1 | \
  974. grep "Location" | awk '{print "https://paste.ubuntu.com"$3}' );;
  975. 'haste' )
  976. share_link=$( curl -X POST -s -d "$(cat $log)" https://hastebin.com/documents | awk -F '"' '{print "https://hastebin.com/"$4}' );;
  977. 'clbin' )
  978. share_link=$( curl -sF 'clbin=<-' https://clbin.com < $log );;
  979. esac
  980.  
  981. # print result info
  982. echo " - $GEEKBENCH_URL" | tee -a $log
  983. echo " - $share_link"
  984. echo ""
  985. rm -f $log_up
  986.  
  987. }
  988.  
  989. log_preupload() {
  990. log_up="$HOME/speedtest_upload.log"
  991. true > $log_up
  992. $(cat speedtest.log 2>&1 | sed -r "s/\x1B\[([0-9]{1,2}(;[0-9]{1,2})?)?[m|K]//g" > $log_up)
  993. }
  994.  
  995. get_ip_whois_org_name(){
  996. #ip=$(curl -s ip.sb)
  997. result=$(curl -s https://rest.db.ripe.net/search.json?query-string=$(curl -s ip.sb))
  998. #org_name=$(echo $result | jq '.objects.object.[1].attributes.attribute.[1].value' | sed 's/\"//g')
  999. org_name=$(echo $result | jq '.objects.object[1].attributes.attribute[1]' | sed 's/\"//g')
  1000. echo $org_name;
  1001. }
  1002.  
  1003. pingtest() {
  1004. local ping_link=$( echo ${1#*//} | cut -d"/" -f1 )
  1005. local ping_ms=$( ping -w 1 -c 1 -q $ping_link | grep 'rtt' | cut -d"/" -f5 )
  1006.  
  1007. # get download speed and print
  1008. if [[ $ping_ms == "" ]]; then
  1009. printf "ping error!"
  1010. else
  1011. printf "%3i.%s ms" "${ping_ms%.*}" "${ping_ms#*.}"
  1012. fi
  1013. }
  1014.  
  1015. cleanup() {
  1016. rm -f test_file_*;
  1017. #rm -f speedtest.py;
  1018. #rm -f speedtest.sh;
  1019. #rm -f tools.py;
  1020. rm -f ip_json.json;
  1021. rm -f geekbench4_claim.url;
  1022. rm -rf geekbench;
  1023. }
  1024.  
  1025. bench_all(){
  1026. region_name="Global"
  1027. print_intro;
  1028. benchinit;
  1029. clear
  1030. next;
  1031. get_system_info;
  1032. print_system_info;
  1033. ip_info4;
  1034. next;
  1035. geekbench4;
  1036. iotest;
  1037. write_io;
  1038. print_speedtest;
  1039. next;
  1040. print_end_time;
  1041. cleanup;
  1042. sharetest clbin;
  1043. }
  1044.  
  1045. usa_bench(){
  1046. region_name="USA"
  1047. print_intro;
  1048. benchinit;
  1049. clear
  1050. next;
  1051. get_system_info;
  1052. print_system_info;
  1053. ip_info4;
  1054. next;
  1055. geekbench4;
  1056. iotest;
  1057. write_io;
  1058. print_speedtest_usa;
  1059. next;
  1060. print_end_time;
  1061. cleanup;
  1062. sharetest clbin;
  1063. }
  1064.  
  1065. europe_bench(){
  1066. region_name="Europe"
  1067. print_intro;
  1068. benchinit;
  1069. clear
  1070. next;
  1071. get_system_info;
  1072. print_system_info;
  1073. ip_info4;
  1074. next;
  1075. geekbench4;
  1076. iotest;
  1077. write_io;
  1078. print_speedtest_europe;
  1079. next;
  1080. print_end_time;
  1081. cleanup;
  1082. sharetest clbin;
  1083. }
  1084.  
  1085. asia_bench(){
  1086. region_name="Asia"
  1087. print_intro;
  1088. benchinit;
  1089. clear
  1090. next;
  1091. get_system_info;
  1092. print_system_info;
  1093. ip_info4;
  1094. next;
  1095. geekbench4;
  1096. iotest;
  1097. write_io;
  1098. print_speedtest_asia;
  1099. next;
  1100. print_end_time;
  1101. cleanup;
  1102. sharetest clbin;
  1103. }
  1104.  
  1105. sa_bench(){
  1106. region_name="South-America"
  1107. print_intro;
  1108. benchinit;
  1109. clear
  1110. next;
  1111. get_system_info;
  1112. print_system_info;
  1113. ip_info4;
  1114. next;
  1115. geekbench4;
  1116. iotest;
  1117. write_io;
  1118. print_speedtest_sa;
  1119. next;
  1120. print_end_time;
  1121. cleanup;
  1122. sharetest clbin;
  1123. }
  1124.  
  1125. ukraine_bench(){
  1126. region_name="Ukraine"
  1127. print_intro;
  1128. benchinit;
  1129. clear
  1130. next;
  1131. get_system_info;
  1132. print_system_info;
  1133. ip_info4;
  1134. next;
  1135. geekbench4;
  1136. iotest;
  1137. write_io;
  1138. print_speedtest_ukraine;
  1139. next;
  1140. print_end_time;
  1141. cleanup;
  1142. sharetest clbin;
  1143. }
  1144. lviv_bench(){
  1145. region_name="Lviv"
  1146. print_intro;
  1147. benchinit;
  1148. clear
  1149. next;
  1150. get_system_info;
  1151. print_system_info;
  1152. ip_info4;
  1153. next;
  1154. geekbench4;
  1155. iotest;
  1156. write_io;
  1157. next;
  1158. print_end_time;
  1159. cleanup;
  1160. sharetest clbin;
  1161. }
  1162. meast_bench(){
  1163. region_name="Middle-East"
  1164. print_intro;
  1165. benchinit;
  1166. clear
  1167. next;
  1168. get_system_info;
  1169. print_system_info;
  1170. ip_info4;
  1171. next;
  1172. geekbench4;
  1173. iotest;
  1174. write_io;
  1175. print_speedtest_meast;
  1176. next;
  1177. print_end_time;
  1178. cleanup;
  1179. sharetest clbin;
  1180. }
  1181. ru_bench(){
  1182. region_name="Russia"
  1183. print_intro;
  1184. benchinit;
  1185. clear
  1186. next;
  1187. get_system_info;
  1188. print_system_info;
  1189. ip_info4;
  1190. next;
  1191. geekbench4;
  1192. iotest;
  1193. write_io;
  1194. print_speedtest_ru;
  1195. next;
  1196. print_end_time;
  1197. cleanup;
  1198. sharetest clbin;
  1199. }
  1200.  
  1201. log="$HOME/speedtest.log"
  1202. true > $log
  1203.  
  1204. case $1 in
  1205. 'info'|'-i'|'--i'|'-info'|'--info' )
  1206. about;sleep 3;next;get_system_info;print_system_info;;
  1207. 'version'|'-v'|'--v'|'-version'|'--version')
  1208. next;about;next;;
  1209. 'gb'|'-gb'|'--gb'|'geek'|'-geek'|'--geek' )
  1210. next;geekbench4;next;cleanup;;
  1211. 'io'|'-io'|'--io'|'ioping'|'-ioping'|'--ioping' )
  1212. next;iotest;write_io;next;;
  1213. 'dd'|'-dd'|'--dd'|'disk'|'-disk'|'--disk' )
  1214. about;ioping;next2;;
  1215. 'speed'|'-speed'|'--speed'|'-speedtest'|'--speedtest'|'-speedcheck'|'--speedcheck' )
  1216. about;benchinit;next;print_speedtest;next;cleanup;;
  1217. 'ip'|'-ip'|'--ip'|'geoip'|'-geoip'|'--geoip' )
  1218. about;benchinit;next;ip_info4;next;cleanup;;
  1219. 'bench'|'-a'|'--a'|'-all'|'--all'|'-bench'|'--bench'|'-Global' )
  1220. bench_all;;
  1221. 'about'|'-about'|'--about' )
  1222. about;;
  1223. 'usa'|'-usa'|'--usa'|'us'|'-us'|'--us'|'USA'|'-USA'|'--USA' )
  1224. usa_bench;;
  1225. 'europe'|'-europe'|'--europe'|'eu'|'-eu'|'--eu'|'Europe'|'-Europe'|'--Europe' )
  1226. europe_bench;;
  1227. 'asia'|'-asia'|'--asia'|'as'|'-as'|'--as'|'Asia'|'-Asia'|'--Asia' )
  1228. asia_bench;;
  1229. 'sa'|'-sa'|'--sa'|'-South-America' )
  1230. sa_bench;;
  1231. 'ukraine'|'-ukraine'|'--ukraine'|'ua'|'-ua'|'--ua'|'ukr'|'-ukr'|'--ukr'|'Ukraine'|'-Ukraine'|'--Ukraine' )
  1232. ukraine_bench;;
  1233. 'lviv'|'-lviv'|'--lviv'|'-Lviv'|'--Lviv' )
  1234. lviv_bench;;
  1235. 'M-East'|'-M-East'|'--M-East'|'-m-east'|'--m-east'|'-meast'|'--meast'|'-Middle-East'|'-me' )
  1236. meast_bench;;
  1237. 'ru'|'-ru'|'--ru'|'rus'|'-rus'|'--rus'|'russia'|'-russia'|'--russia'|'Russia'|'-Russia'|'--Russia' )
  1238. ru_bench;;
  1239. '-s'|'--s'|'share'|'-share'|'--share' )
  1240. bench_all;
  1241. is_share="share"
  1242. if [[ $2 == "" ]]; then
  1243. sharetest ubuntu;
  1244. else
  1245. sharetest $2;
  1246. fi
  1247. ;;
  1248. 'debug'|'-d'|'--d'|'-debug'|'--debug' )
  1249. get_ip_whois_org_name;;
  1250. *)
  1251. bench_all;;
  1252. esac
  1253.  
  1254.  
  1255.  
  1256. if [[ ! $is_share == "share" ]]; then
  1257. case $2 in
  1258. 'share'|'-s'|'--s'|'-share'|'--share' )
  1259. if [[ $3 == '' ]]; then
  1260. sharetest ubuntu;
  1261. else
  1262. sharetest $3;
  1263. fi
  1264. ;;
  1265. esac
  1266. fi
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement