/ Published in: Perl
URL: http://www.richardjameskendall.com
Expand |
Embed | Plain Text
# subroutine: ping_machine # accepts: hostname/ip address, timeout(ms), # of echos to send # returns an array: # 0: status: DNS_FAIL/PING_FAIL/PING_PARTIALLY_OKAY/PING_OKAY # 1: ip address of the host (v4) # 2: min delay (ms) # 3: max delay (ms) # 4: ave delay (ms) # calls the windows ping utility sub ping_machine { my @return_array; my $status; my $ip_address; my $max; my $min; my $ave; my $host = @_[0]; my $timeout = @_[1]; my $packets = @_[2]; while(<PING>) { if(/could not find/) { $status = "DNS_FAIL"; } if(/\[([0-9\.]+)\]/) { $ip_address = $1; } if(/Packets\: Sent \= ([0-9]+)\, Received \= ([0-9]+)\, Lost \= ([0-9]+)/) { if($1 eq $2) { $status = "PING_OKAY"; } else { if($1 eq $3) { $status = "PING_FAIL"; } else { $status = "PING_PARTIALLY_OKAY"; } } } if(/Minimum \= ([0-9]+)ms\, Maximum \= ([0-9]+)ms\, Average \= ([0-9]+)/) { $min = $1; $max = $2; $ave = $3; } } $return_array[0] = $status; $return_array[1] = $ip_address; $return_array[2] = $min; $return_array[3] = $max; $return_array[4] = $ave; return @return_array; }
You need to login to post a comment.
