App-SpeedTest
view release on metacpan or search on metacpan
* Make ping-list-length settable
* Do not truncate server list when a specific server is selected
* It's 2020
0.22 2019-09-02
* Add --list-cc
* Add cpanfile
* Add -U / --skip-undef
* Provide cpanfile
* Add help and options to examples/speedtest-graph.pl
* Fix warning when using --no-upload or --no-download (issue#13)
0.21 2019-03-21
* Add --csv-eol-unix
0.20 2019-01-01
* Versions
* It's 2017
* Show a ranked summary of the tries with --try
* It's 2018
* Deal with proxy settings in env
0.05 2014-10-14
* Allow test on multiple servers
* Put on github
0.04 2014-10-10
* Require 5.12.0 instead of 5.16.3
* Options -q and -Q accept count
* Verbose levels
* Values for min and max speeds druing test
* Speed report improvement
* Use random data in upload
* Remove ignored servers from list
0.03 2014-10-10
* First checkin to git
lib/App/SpeedTest.pm view on Meta::CPAN
=head1 SYNOPSIS
$ speedtest [ --no-geo | --country=NL ] [ --list | --ping ] [ options ]
$ speedtest --list
$ speedtest --ping --country=BE
$ speedtest
$ speedtest -s 4358
$ speedtest --url=http://ookla.extraip.net
$ speedtest -q --no-download
$ speedtest -Q --no-upload
=head1 DESCRIPTION
The provided perl script is a command-line interface to the
L<speedtest.net|http://www.speedtest.net/> infrastructure so that
flash is not required
It was written to feature the functionality that speedtest.net offers
without the overhead of flash or java and the need of a browser.
lib/App/SpeedTest.pm view on Meta::CPAN
X<--try>
Use the top # (based on lowest latency or shortest distance) from the list
to do all required tests.
$ speedtest -T3 -c NL -Q2
Testing for 80.x.y.z : XS4ALL Internet BV (NL)
Using 13218: 26.52 km 25 ms XS4ALL Internet BV
Test download .. Download 31.807 Mbit/s
Test upload .. Upload 86.587 Mbit/s
Using 15850: 26.09 km 25 ms QTS Data Centers
Test download .. Download 80.763 Mbit/s
Test upload .. Upload 77.122 Mbit/s
Using 11365: 26.09 km 27 ms Vancis
Test download .. Download 106.022 Mbit/s
Test upload .. Upload 82.891 Mbit/s
Rank 01: Server: 11365 26.09 km 27 ms, DL: 106.022 UL: 82.891
Rank 02: Server: 15850 26.09 km 25 ms, DL: 80.763 UL: 77.122
Rank 03: Server: 13218 26.52 km 25 ms, DL: 31.807 UL: 86.587
$ speedtest -1v0 -T5
DL: 200.014 Mbit/s, UL: 159.347 Mbit/s, SRV: 13218
DL: 203.599 Mbit/s, UL: 166.247 Mbit/s, SRV: 15850
DL: 207.249 Mbit/s, UL: 134.957 Mbit/s, SRV: 11365
DL: 195.490 Mbit/s, UL: 172.109 Mbit/s, SRV: 5972
lib/App/SpeedTest.pm view on Meta::CPAN
Specify the ID of the server to test against. This ID can be taken from the
output of L</--list> or L</--ping>. Using this option prevents fetching the
complete server list and calculation of distances. It also enables you to
always test against the same server.
$ speedtest -1s4358
Testing for 80.x.y.z : XS4ALL Internet BV ()
Using 4358: 52.33 km 64 ms KPN
Test download ........................................Download: 92.633 Mbit/s
Test upload ........................................Upload: 92.552 Mbit/s
DL: 92.633 Mbit/s, UL: 92.552 Mbit/s
This argument may be repeated to test against multile servers, more or less
like specifying your own top x (as with C<-T>).
$ speedtest -s 22400 -s 1208 -s 13218
Testing for 185.x.y.z : Freedom Internet BV ()
Using 13218: 80.15 km 32 ms XS4ALL Internet BV
Test download ........................................Download 66.833 Mbit/s
Test upload ........................................Upload 173.317 Mbit/s
Using 1208: 51.19 km 37 ms Qweb | Full-Service Hosting
Test download ........................................Download 52.077 Mbit/s
Test upload ........................................Upload 195.833 Mbit/s
Using 22400: 80.15 km 46 ms Usenet.Farm
Test download ........................................Download 96.341 Mbit/s
Test upload ........................................Upload 203.306 Mbit/s
Rank 01: Server: 22400 80.15 km 46 ms, DL: 96.341 UL: 203.306
Rank 02: Server: 1208 51.19 km 37 ms, DL: 52.077 UL: 195.833
Rank 03: Server: 13218 80.15 km 32 ms, DL: 66.833 UL: 173.317
If you pass a filename, it is expected to reflect a server-like structure as
received from the speedtest server-list, possibly completed with upload- and
download URL's. You can only pass one filename not consisting of all digits.
If you do, all remaining C<-s> arguments are ignored.
{ cc => "NL",
country => "Netherlands",
host => "unlisted.host.amsterdam:8080",
id => 9999,
lat => "52.37316",
lon => "4.89122",
name => "Amsterdam",
ping => 20.0,
sponsor => "Dam tot Damloop",
url => "http://unlisted.host.amsterdam/speedtest/speedtest/upload.php",
url2 => "http://unlisted.host.amsterdam/speedtest/speedtest/upload.php",
dl_list => [
"http://unlisted.host.amsterdam/files/128.bin",
"http://unlisted.host.amsterdam/files/256.bin",
# 40 URL's pointing to files in increasing size
"http://unlisted.host.amsterdam/files/2G.bin",
],
ul_list => [
# 40 URL's
],
lib/App/SpeedTest.pm view on Meta::CPAN
=item -t# | --timeout=#
X<-t>
X<--timeout>
Specify the maximum timeout in seconds.
=item -d | --download
X<-d>
X<--download>
Run the download tests. This is default unless L</--upload> is passed.
=item -u | --upload
X<-u>
X<--upload>
Run the upload tests. This is default unless L</--download> is passed.
=item -q[#] | --quick[=#] | --fast[=#]
X<-q>
X<--quick>
X<--fast>
Don't run the full test. The default test runs 40 tests, sorting on
increasing test size (and thus test duration). Long(er) tests may take
too long on slow connections without adding value. The default value
for C<-q> is 20 but any value between 1 and 40 is allowed.
-l --list list test servers in chosen country sorted by distance
-p --ping[=40] list test servers in chosen country sorted by latency
--url show server url in list
-s --server=nnn use testserver with id nnn
--server=file use testserver from file
-t --timeout=nnn set server timeout to nnn seconds
--url=sss use specific server url (do not scan) ext php
--mini=sss use specific server url (do not scan) ext from sss
--download test download speed (default true)
--upload test upload speed (default true)
-q --quick[=20] do a quick test (only the fastest 20 tests)
-Q --realquick do a real quick test (only the fastest 10 tests)
-T --try[=5] try all tests on the n fastest servers
-U --skip-undef skip results with no actual measurements
-v --verbose[=1] set verbosity
--simple alias for -v0
--ip show IP for server
-V --version show version and exit
-? --help show this help
--man show the builtin manual (requires nroff)
--info show the builtin manual as plain text
$p --list
$p --ping --country=BE
$p
$p -s 4358
$p --url=http://ookla.extraip.net
$p -q --no-download
$p -Q --no-upload
EOH
exit $err;
} # usage
use Getopt::Long qw(:config bundling noignorecase);
my $opt_c = "";
my $opt_v = 1;
my $opt_d = 1;
my $opt_u = 1;
"p|ping:40" => \my $opt_ping,
"url:s" => \my $url,
"ip!" => \my $ip,
"B|bytes" => sub { $unit = [ 8, "byte" ] },
"T|try:5" => \$opt_T,
"s|server=s" => \my @server,
"t|timeout=i" => \my $timeout,
"d|download!" => \$opt_d,
"u|upload!" => \$opt_u,
"q|quick|fast:20" => \$opt_q,
"Q|realquick:10" => \$opt_q,
"U|skip-undef!" => \my $opt_U,
"m|mini=s" => \my $mini,
"source=s" => \my $source, # NYI
) or usage (1);
$opt_CNL and $opt_C++;
$opt_C || $opt_P and $opt_v = 0;
binmode STDOUT, ":encoding(utf-8)";
# Speedtest.net defines Mbit/s and kbit/s using 1000 as multiplier,
# https://support.speedtest.net/entries/21057567-What-do-mbps-and-kbps-mean-
my $k = 1000;
my $config = get_config ();
my $client = $config->{"client"} or die "Config saw no client\n";
my $times = $config->{"times"} or die "Config saw no times\n";
my $downld = $config->{"download"} or die "Config saw no download\n";
my $upld = $config->{"upload"} or die "Config saw no upload\n";
$opt_v > 3 and ddumper {
client => $client,
times => $times,
down => $downld,
up => $upld,
};
if ($url || $mini) {
$opt_g = 0;
$opt_c = "";
my $t0 = [ gettimeofday ];
my $rsp = $ua->request (HTTP::Request->new (GET => $mini));
$ping = tv_interval ($t0);
$rsp->is_success or die $rsp->status_line . "\n";
my $tree = HTML::TreeBuilder->new ();
$tree->parse_content ($rsp->content) or die "Cannot parse\n";
my $ext = "";
for ($tree->look_down (_tag => "script")) {
my $c = ($_->content)[0] or next;
ref $c eq "ARRAY" && $c->[0] &&
$c->[0] =~ m{\b (?: upload_? | config ) Extension
\s*: \s* "? ([^"\s]+) }xi or next;
$ext = $1;
last;
}
$ext or die "No ext found\n";
($url = $mini) =~ s{/*$}{/speedtest/upload.$ext};
$sponsor = $_->as_text for $tree->look_down (_tag => "title");
$name ||= $_->as_text for $tree->look_down (_tag => "h1");
$name ||= "Speedtest mini";
}
else {
$name = "Local";
$url =~ m{/\w+\.\w+$} or $url =~ s{/?$}{/speedtest/upload.php};
my $t0 = [ gettimeofday ];
my $rsp = $ua->request (HTTP::Request->new (GET => $url));
$ping = tv_interval ($t0);
$rsp->is_success or die $rsp->status_line . "\n";
}
(my $host = $url) =~ s{^\w+://([^/]+)(?:/.*)?}{$1};
$url = {
cc => "",
country => "",
dist => "0.0",
$opt_a = 1;
unless ($server[0] =~ m{^[0-9]+$}) {
open my $fh, "<", $server[0] or die;#usage (1);
my $data = do { local $/; <$fh>; };
print $data;
$data =~ m/^\s*\{\s*(['"]?)cc\1\s*=>\s*(["'])[A-Z]{1,3}\2\s*,/ &&
$data =~ m/\s(["']?)id\1\s*=>\s*[0-9]+\s*,/ or die;#usage (1);
$data = eval $data;
$data->{dist} = distance ($client->{lat}, $client->{lon},
$data->{lat}, $data->{lon});
($data->{url0} = $data->{url}) =~ s{/speedtest/upload.*}{};
$url = $data;
}
}
else {
if ($opt_c) {
$opt_c = uc $opt_c;
}
elsif ($opt_g) { # Try GeoIP
$opt_v > 5 and say STDERR "Testing Geo location";
my $url = "http://www.geoiptool.com";
my $speed = 8 * $sz / $elapsed / $k / $k;
push @rslt, [ $sz, $elapsed, $speed ];
$opt_v and print STDERR ".";
$opt_v > 2 and printf STDERR "\n%12.3f %s (%7d) ", $speed, $url, $sz;
}
$dl = result ("Download", $host, scalar @url, @rslt);
}
my $ul = "-";
if ($opt_u) {
$opt_v and print STDERR "Test upload ";
my @data = (0 .. 9, "a" .. "Z", "a" .. "z"); # Random pure ASCII data
my $data = join "" => map { $data[int rand $#data] } 0 .. 4192;
$data = "content1=".($data x 8192); # Total length just over 4 Mb
my @rslt;
my $url = $host->{url}; # .php, .asp, .aspx, .jsp
# see $upld->{mintestsize} and $upld->{maxchunksize} ?
my @size = map { $_ * 1000 }
# ((256) x 10, (512) x 10, (1024) x 10, (4096) x 10);
((256) x 10, (512) x 10, (1024) x 5, (2048) x 5, (4096) x 5, (8192) x 5);
$opt_q and splice @size, $opt_q;
);
# 4601 => {
# cc => 'NL',
# country => 'Netherlands',
# dist => '38.5028663935342602', # added later
# id => 4601,
# lat => '52.2167',
# lon => '5.9667',
# name => 'Apeldoorn',
# sponsor => 'Solcon Internetdiensten N.V.',
# url => 'http://speedtest.solcon.net/speedtest/upload.php',
# url2 => 'http://ooklaspeedtest.solcon.net/speedtest/upload.php'
# },
return map { $_->{id} => $_ } @{$xml->{settings}{servers}{server}};
} # get_servers
sub distance {
my ($lat_c, $lon_c, $lat_s, $lon_s) = @_;
my $rad = 6371; # km
# Convert angles from degrees to radians
my %list = get_servers ();
if (my $iid = $config->{"server-config"}{ignoreids}) {
$opt_v > 3 and warn "Removing servers $iid from server list\n";
delete @list{split m/\s*,\s*/ => $iid};
}
$opt_a or delete @list{grep { $list{$_}{cc} ne $opt_c } keys %list};
%list or die "No servers in $opt_c found\n";
for (values %list) {
$_->{dist} = distance ($client->{lat}, $client->{lon},
$_->{lat}, $_->{lon});
($_->{url0} = $_->{url}) =~ s{/speedtest/upload.*}{};
$opt_v > 7 and ddumper $_;
}
return %list;
} # servers
sub servers_by_ping {
my %list = servers;
my @list = values %list;
$opt_v > 1 and say STDERR "Finding fastest host out of @{[scalar @list]} hosts for $opt_c ...";
my $pa = LWP::UserAgent->new (
=head1 SYNOPSIS
$ speedtest [ --no-geo | --country=NL ] [ --list | --ping ] [ options ]
$ speedtest --list
$ speedtest --ping --country=BE
$ speedtest
$ speedtest -s 4358
$ speedtest --url=http://ookla.extraip.net
$ speedtest -q --no-download
$ speedtest -Q --no-upload
=head1 DESCRIPTION
The provided perl script is a command-line interface to the
L<speedtest.net|http://www.speedtest.net/> infrastructure so that
flash is not required
It was written to feature the functionality that speedtest.net offers
without the overhead of flash or java and the need of a browser.
X<--try>
Use the top # (based on lowest latency or shortest distance) from the list
to do all required tests.
$ speedtest -T3 -c NL -Q2
Testing for 80.x.y.z : XS4ALL Internet BV (NL)
Using 13218: 26.52 km 25 ms XS4ALL Internet BV
Test download .. Download 31.807 Mbit/s
Test upload .. Upload 86.587 Mbit/s
Using 15850: 26.09 km 25 ms QTS Data Centers
Test download .. Download 80.763 Mbit/s
Test upload .. Upload 77.122 Mbit/s
Using 11365: 26.09 km 27 ms Vancis
Test download .. Download 106.022 Mbit/s
Test upload .. Upload 82.891 Mbit/s
Rank 01: Server: 11365 26.09 km 27 ms, DL: 106.022 UL: 82.891
Rank 02: Server: 15850 26.09 km 25 ms, DL: 80.763 UL: 77.122
Rank 03: Server: 13218 26.52 km 25 ms, DL: 31.807 UL: 86.587
$ speedtest -1v0 -T5
DL: 200.014 Mbit/s, UL: 159.347 Mbit/s, SRV: 13218
DL: 203.599 Mbit/s, UL: 166.247 Mbit/s, SRV: 15850
DL: 207.249 Mbit/s, UL: 134.957 Mbit/s, SRV: 11365
DL: 195.490 Mbit/s, UL: 172.109 Mbit/s, SRV: 5972
Specify the ID of the server to test against. This ID can be taken from the
output of L</--list> or L</--ping>. Using this option prevents fetching the
complete server list and calculation of distances. It also enables you to
always test against the same server.
$ speedtest -1s4358
Testing for 80.x.y.z : XS4ALL Internet BV ()
Using 4358: 52.33 km 64 ms KPN
Test download ........................................Download: 92.633 Mbit/s
Test upload ........................................Upload: 92.552 Mbit/s
DL: 92.633 Mbit/s, UL: 92.552 Mbit/s
This argument may be repeated to test against multile servers, more or less
like specifying your own top x (as with C<-T>).
$ speedtest -s 22400 -s 1208 -s 13218
Testing for 185.x.y.z : Freedom Internet BV ()
Using 13218: 80.15 km 32 ms XS4ALL Internet BV
Test download ........................................Download 66.833 Mbit/s
Test upload ........................................Upload 173.317 Mbit/s
Using 1208: 51.19 km 37 ms Qweb | Full-Service Hosting
Test download ........................................Download 52.077 Mbit/s
Test upload ........................................Upload 195.833 Mbit/s
Using 22400: 80.15 km 46 ms Usenet.Farm
Test download ........................................Download 96.341 Mbit/s
Test upload ........................................Upload 203.306 Mbit/s
Rank 01: Server: 22400 80.15 km 46 ms, DL: 96.341 UL: 203.306
Rank 02: Server: 1208 51.19 km 37 ms, DL: 52.077 UL: 195.833
Rank 03: Server: 13218 80.15 km 32 ms, DL: 66.833 UL: 173.317
If you pass a filename, it is expected to reflect a server-like structure as
received from the speedtest server-list, possibly completed with upload- and
download URL's. You can only pass one filename not consisting of all digits.
If you do, all remaining C<-s> arguments are ignored.
{ cc => "NL",
country => "Netherlands",
host => "unlisted.host.amsterdam:8080",
id => 9999,
lat => "52.37316",
lon => "4.89122",
name => "Amsterdam",
ping => 20.0,
sponsor => "Dam tot Damloop",
url => "http://unlisted.host.amsterdam/speedtest/speedtest/upload.php",
url2 => "http://unlisted.host.amsterdam/speedtest/speedtest/upload.php",
dl_list => [
"http://unlisted.host.amsterdam/files/128.bin",
"http://unlisted.host.amsterdam/files/256.bin",
# 40 URL's pointing to files in increasing size
"http://unlisted.host.amsterdam/files/2G.bin",
],
ul_list => [
# 40 URL's
],
=item -t# | --timeout=#
X<-t>
X<--timeout>
Specify the maximum timeout in seconds.
=item -d | --download
X<-d>
X<--download>
Run the download tests. This is default unless L</--upload> is passed.
=item -u | --upload
X<-u>
X<--upload>
Run the upload tests. This is default unless L</--download> is passed.
=item -q[#] | --quick[=#] | --fast[=#]
X<-q>
X<--quick>
X<--fast>
Don't run the full test. The default test runs 40 tests, sorting on
increasing test size (and thus test duration). Long(er) tests may take
too long on slow connections without adding value. The default value
for C<-q> is 20 but any value between 1 and 40 is allowed.
( run in 2.851 seconds using v1.01-cache-2.11-cpan-b16cb0d3907 )