Is there a Perl module for checking Internet connection speed?

Does anyone know a module for checking the speed of an Internet connection?

+4
source share
2 answers

Speed ​​in bandwidth? Or as in latency? For the latter, just use Net :: Ping .

For bandwidth, I don’t know if something is ready, there are 2 approaches:

  • You can try using ibmonitor

  • Otherwise, to measure the bandwidth, find a website that can measure bandwidth by downloading a large file (or find such a large file on a high-performance website); start the timer, start downloading this file (for example, using LWP or any other module that you want - or Net :: FTP if your file is on an FTP site) - measure how much time it takes and divide by file size.

    The same logic is used to measure download bandwidth, but instead of finding a large file, you need to find a place on the Internet (for example, a public repository) that will allow it to be downloaded.

+8
source
#!/usr/bin/env perl use warnings; use strict; use 5.010; use Time::HiRes qw(gettimeofday tv_interval); use LWP::Simple; use File::stat; my %h = ( '500x500' => 505544, '750x750' => 1118012, '1000x1000' => 1986284, '1500x1500' => 4468241, '2000x2000' => 7907740, ); my $pixel = '1000x1000'; my $url_file = 'http://speedserver/file'.$pixel.'.jpg'; my $file = 'file'.$pixel.'.jpg'; unlink $file or die $! if -e $file; my $start = gettimeofday; my $response = getstore( $url_file, $file ); my $end = gettimeofday; open my $fh, '>>', 'speed_test.txt' or die $!; say $fh scalar localtime; if ( not is_success $response ) { say $fh "error occured:"; say $fh "HTTP response code = $response"; } else { my $size = stat( $file )->size if -e $file; $size ||= 0; if ( $size == $h{$pixel} ) { my $bit = $size * 8; my $time = $end - $start; my $kbps = int( ( $bit / $time ) / 1000 ); say $fh "$kbps kbit/s"; say $fh "$pixel : $size"; } else { say $fh "error occured:"; say $fh "file_size is $size - file_size expected $h{$pixel}"; } } say $fh ""; close $fh; 
+4
source

Source: https://habr.com/ru/post/1307930/


All Articles