MOON
Server: Apache/2.2.31 (Unix) mod_ssl/2.2.31 OpenSSL/0.9.8e-fips-rhel5 mod_bwlimited/1.4
System: Linux csr818.wilogic.com 2.6.18-419.el5xen #1 SMP Fri Feb 24 22:50:37 UTC 2017 x86_64
User: digitals (531)
PHP: 5.4.45
Disabled: NONE
Upload Files
File: //scripts.20110531.215904.25158/pingtest
#!/usr/bin/perl
# cpanel10 - pingtest                        Copyright(c) 1997-2006 cPanel, Inc.
#                                                           All rights Reserved.
# copyright@cpanel.net                                         http://cpanel.net
# This code is subject to the cPanel license. Unauthorized copying is prohibited

$| = 1;

use strict;
use IPC::Open3;

if (! -e '/root/.cpupdates/pingtimes') {
    mkdir('/root/.cpupdates',0700);
    mkdir('/root/.cpupdates/pingtimes',0700);
}

my @HOSTS;
if (open my $mirrorlst_fh, '<', '/root/.cpupdates/mirrors.lst') {
    while(<$mirrorlst_fh>) {
        chomp;
        m/([^\:]+):\/\/([^\/]+)(\S+)/;
        push @HOSTS, $2;
    }
    close $mirrorlst_fh;
}

my $now = time();
my $child = 0;

foreach my $host (@HOSTS) {

    next if (((stat('/root/.cpupdates/pingtimes/' . $host ))[9] + (86400 * 15)) > $now);

    if ($child <= 15) {
        if (my $pid = fork()) {
            $child++;
            print '.';
            #master
        } else {
            my $pingtime = pinghost($host);
            if (open my $pt_fh, '>', '/root/.cpupdates/pingtimes/' . $host) {
                print {$pt_fh} $pingtime;
                close $pt_fh;
            }
            else {
                warn "Unable to write /root/.cpupdates/pingtimes/$host: $!";
            }
            exit;
        }
    } else {
        sleep 1;
    }

    while (waitpid(-1, 1) > 0) {
        $child--;
    }
}

while (waitpid(-1, 0) > 0) {
    $child--;
}

sub pinghost {
    my($host) = @_;
    my($pingtime);

    open(WNULL,'>/dev/null');
    open(RNULL,'</dev/null');

    open3('<&RNULL',\*PING,'>&WNULL','ping','-w','3','-c','2',$host);
    while(<PING>) {
        if (/[\d\.]+\/([\d\.]+)/) {
            $pingtime = $1;
        }
    }
    close(PING);
    if (!$pingtime ) { $pingtime = 1000; }

    close(RNULL);
    close(WNULL);

    return $pingtime;
}