有 Perl 模块来测试互联网连接速度吗?

发布于 2024-08-30 08:09:37 字数 25 浏览 2 评论 0原文

有人知道测试互联网连接速度的模块吗?

Does anybody know a module to test the speed of internet-connection?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

游魂 2024-09-06 08:09:37

速度与带宽一样吗?或者像延迟一样?对于后者,只需使用 Net::Ping

对于带宽,不知道有没有现成的,有两种方法:

  1. 你可以尝试利用ibmonitor

  2. 否则,要测量下载带宽,请找到一个以下网站:让您可以通过下载大文件(或在高性能站点上找到如此大的文件)来测量带宽;启动计时器,开始下载该文件(例如使用 LWP 或您希望的任何其他模块- 或 Net::FTP(如果您的文件位于 FTP 站点上) - 测量需要多长时间并除以文件大小。

    测量上传带宽的逻辑类似,但您需要在互联网上找到一个允许上传文件的位置(例如公共存储库),而不是查找大文件。

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

For bandwidth, I don't know if there's anything ready made, there's 2 approaches:

  1. You can try to leverage ibmonitor

  2. Otherwise, to measure download bandwidth find a web site that lets you measure bandwidth by downloading a large file (or find such a large file on high-performance site); start the timer, start downloading that file (e.g. using LWP or any other module you wish - or Net::FTP if your file is on FTP site) - measure how long it takes and divide by the file size.

    Similar logic for measuring upload bandwidth, but instead of finding large file, you need to find a place on the internet (like a public repository) that'd allow uploading one.

眼中杀气 2024-09-06 08:09:37
#!/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;
#!/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;
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文