Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/bin/bash
- # Copyright (C) 2016-2018 Uco Mesdag
- # Usage: sh speedtest
- test_result=$( mktemp )
- YELLOW='\033[0;33m'
- GREEN='\033[0;32m'
- BLUE='\033[0;34m'
- RED='\033[0;31m'
- BOLD='\033[1m'
- NC='\033[0m'
- curl -o /tmp/speedtest https://raw.githubusercontent.com/sivel/speedtest-cli/master/speedtest.py >/dev/null 2>&1
- chmod +x /tmp/speedtest
- clear
- if [ "x$(echo $1 | grep '^[0-9]\{1,4\}$')" == "x" ]; then
- echo " Retrieving server list..."
- result=$(/tmp/speedtest --list 2>/dev/null | head -n10 )
- if [ $(echo ${result} | grep -c Error) -ne 0 ]; then
- exit 1
- fi
- clear
- echo -e "${result}\n"
- read -p " Enter the server id you want to test against: " server_id
- clear
- else
- server_id=$1
- fi
- if [ "x$(echo ${server_id} | grep '^[0-9]\{1,4\}$')" != "x" ]; then
- /tmp/speedtest --server ${server_id} --share --secure | tee ${test_result}
- else
- /tmp/speedtest --share --secure | tee ${test_result}
- fi
- rm /tmp/speedtest
- get_ip_location() {
- result=$(curl -s -X GET http://ip-api.com/line/$1?fields=countryCode,city)
- country_code=$(echo -e "${result}" | sed '1!d')
- city=$(echo -e "${result}" | sed '2!d')
- if [ "x${country_code}" != "x" ] && [ "${country_code}" != "Unknown" ]; then
- country_code=" (${country_code})"
- fi
- if [ "${city}" == "Unknown" ]; then
- city=""
- fi
- echo "${city}${country_code}"
- }
- parse_result() {
- ip=$(cat ${test_result} | grep 'Testing from' | grep -oE "[0-9]+.[0-9]+.[0-9]+.[0-9]+")
- location=$(get_ip_location $ip)
- provider=$(cat ${test_result} | grep 'Testing from' | cut -d ' ' -f 3-| rev | cut -d ' ' -f 2- | rev)
- ping=$(cat ${test_result} | grep ms | rev | cut -d ' ' -f 1-2 | rev)
- download=$(cat ${test_result} | grep Download | rev | cut -d ' ' -f 1-2 | rev)
- upload=$(cat ${test_result} | grep Upload | rev | cut -d ' ' -f 1-2 | rev)
- image_url=$(cat ${test_result} | grep Share | rev | cut -d ' ' -f 1 | rev)
- clear
- echo -e "${BOLD} ${provider} - ${location}${NC}"
- echo -e "${GREEN} 〇\t${ping}${NC}"
- echo -e "${RED} ⬇\t${download}${NC}"
- echo -e "${BLUE} ⬆\t${upload}${NC}"
- echo -e "${YELLOW}\n${image_url}${NC}"
- }
- parse_result
- rm ${test_result}
- exit 0
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement