有人知道测试互联网连接速度的模块吗?
答案 0 :(得分:8)
带宽速度如何?或者像延迟一样?对于后者,只需使用Net::Ping。
对于带宽,我不知道是否有任何现成的,有两种方法:
答案 1 :(得分:4)
#!/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;