Ispeed v1.1 - Medidor de velocidade de download

Publicado por Tiago Weber 24/06/2009

[ Hits: 7.661 ]

Download ispeed




Este script mede a velocidade de download na internet baseado no cálculo da média de
velocidade de download enquanto o wget baixa um grande arquivo de um servidor.

O arquivo que o script tentará baixar pode ser alterado pelo usuário através da edição da
variável "link". Após a medição, o script exibe uma tabela de referência mostrando
aproximadente quanto tempo o usuário levaria para baixar alguns tipos de arquivos.

A versão 1.1 corrige o bug da medição de velocidades superiores a 1Mbyte/s.

  



Esconder código-fonte

#! /bin/bash
# -----------------------------------------------------------------------
# Script: Internet Speed (Ispeed)
# Version: 1.1
# Author: Tiago Oliveira Weber
# E-mail: towalker@gmail.com                 
# 
# Description: This script measures the internet download speed based on
# the download speed mean of wget while downloading a big file from a 
# server. 
# The file the script is going to try to download can be changed by the 
# user in the "link" variable.
# -----------------------------------------------------------------------

# Define links
link=ftp://ftp.slackware-brasil.com.br/slackware-12.0-iso/slackware-12.0-install-d1.iso

# Start to download a file
wget -O /tmp/tempfile -o /tmp/ispeed.log -b $link;
echo -e "\n Wait a few seconds while your internet is being measured"
# Reads values from the log
sleep 10
awk '$5 ~ ".........." {print $8}' /tmp/ispeed.log > /tmp/ispeed2.log
tail -10 /tmp/ispeed2.log > /tmp/ispeed3.log
cut -f 1 -d "K" -s /tmp/ispeed3.log > /tmp/ispeed4.log 
cut -f 1 -d "M" -s /tmp/ispeed3.log > /tmp/ispeed5.log

# Counting ispeed5.log lines
wc -l /tmp/ispeed5.log > /tmp/ispeed6.log
cut -f 1 -d " " -s /tmp/ispeed6.log > /tmp/ispeed7.log
read nm < /tmp/ispeed7.log #nm is the number of variables with M bytes

# summing both logs
cat /tmp/ispeed5.log >> /tmp/ispeed4.log

# Put values into variables
count=1; 
while read line; do
   eval var$count=$line
       count=`expr $count + 1`;
done   < /tmp/ispeed4.log; 

# Round values

varb1=`echo $var1|awk '{print int($1+0.5)}'`
varb2=`echo $var2|awk '{print int($1+0.5)}'`
varb3=`echo $var3|awk '{print int($1+0.5)}'`
varb4=`echo $var4|awk '{print int($1+0.5)}'`
varb5=`echo $var5|awk '{print int($1+0.5)}'`
varb6=`echo $var6|awk '{print int($1+0.5)}'`
varb7=`echo $var7|awk '{print int($1+0.5)}'`
varb8=`echo $var8|awk '{print int($1+0.5)}'`
varb9=`echo $var9|awk '{print int($1+0.5)}'`
varb10=`echo $var10|awk '{print int($1+0.5)}'`

#multiply by 1e3 the M values
varlimit=10
eval kstop=`expr 10 - $nm + 1`;

if [ 1 -lt $kstop ]
then
    varc1=$varb1;
else
    eval varc1=`expr $varb1 \* 1000`
fi 
if [ 2 -lt $kstop ]
then
    varc2=$varb2;
else
    eval varc2=`expr $varb2 \* 1000`
fi 
if [ 3 -lt $kstop ]
then
    varc3=$varb3;
else
    eval varc3=`expr $varb3 \* 1000`
fi 
if [ 4 -lt $kstop ]
then
    varc4=$varb4;
else
    eval varc4=`expr $varb4 \* 1000`
fi 
if [ 5 -lt $kstop ]
then
    varc5=$varb5;
else
    eval varc5=`expr $varb5 \* 1000`
fi 

if [ 6 -lt $kstop ]
then
    varc6=$varb6;
else
    eval varc6=`expr $varb6 \* 1000`
fi 
if [ 7 -lt $kstop ]
then
    varc7=$varb7;
else
    eval varc7=`expr $varb7 \* 1000`
fi 
if [ 8 -lt $kstop ]
then
    varc8=$varb8;
else
    eval varc8=`expr $varb8 \* 1000`
fi 
if [ 9 -lt $kstop ]
then
    varc9=$varb9;
else
    eval varc9=`expr $varb9 \* 1000`
fi 
if [ 10 -lt $kstop ]
then
    varc10=$varb10;
else
    eval varc10=`expr $varb10 \* 1000`
fi 

# calculate the mean
eval sum=`expr $varc1 + $varc2 + $varc3 + $varc4 + $varc5 + $varc6 + $varc7 + $varc8 + $varc9 + $varc10`;

eval mean_kbytes=`expr $sum / 10`;
eval mean_kbits=`expr $mean_kbytes \* 8`;

# Display Results
clear
echo    "                     Measurement Results                       "
echo -e "_______________________________________________________________"
echo -e " Download Speed is: $mean_kbytes Kbytes/s or $mean_kbits Kbits/s \n \n";

# Comparisons
mp3_size_kbytes=5000
videoclip_size_kbytes=35000
movie_size_kbytes=800000
cdrom_size_kbytes=737000
dvd_size_kbytes=4700000

eval time_mp3_min=`expr $mp3_size_kbytes / $mean_kbytes / 60`
eval time_videoclip_min=`expr $videoclip_size_kbytes / $mean_kbytes / 60`
eval time_movie_min=`expr $movie_size_kbytes / $mean_kbytes / 60`
eval time_cdrom_min=`expr $cdrom_size_kbytes / $mean_kbytes / 60`
eval time_dvd_min=`expr $dvd_size_kbytes / $mean_kbytes / 60`

# Display Comparisons

echo -e "                Reference Download Time Table                     "
echo -e "_______________________________________________________________"
echo -e "  Type \t \t Size (Kbytes) \t \t Time (minutes)"
echo -e "  Music (mp3) \t $mp3_size_kbytes \t \t \t $time_mp3_min"
echo -e "  Videoclip \t $videoclip_size_kbytes \t \t \t $time_videoclip_min"
echo -e "  Movie \t $movie_size_kbytes \t \t $time_movie_min"
echo -e "  Cd-Rom \t $cdrom_size_kbytes \t \t $time_cdrom_min"
echo -e "  DVD \t \t $dvd_size_kbytes \t \t $time_dvd_min" 

# Finish the temporary activities
killall -9 wget
rm /tmp/ispeed.log
rm /tmp/ispeed2.log
rm /tmp/ispeed3.log
rm /tmp/ispeed4.log
rm /tmp/tempfile


Scripts recomendados

Envio de email via console

Atualizando /home dos usuários em rede.(GNOME)

Administração de Usuários

dhcp com area grafica

Invertendo strings usando vetores


  

Comentários

Nenhum comentário foi encontrado.


Contribuir com comentário




Patrocínio

Site hospedado pelo provedor RedeHost.
Linux banner

Destaques

Artigos

Dicas

Tópicos

Top 10 do mês

Scripts