#!/usr/bin/perl -w =head1 NAME ping_linux.pl - This script works on Linux system pings a host and returns statistics data. =head1 VERSION Version 1.0 =head1 AUTHOR Gaurav Dubey (gaurav.d@ronankiinfotech.com =head1 SYNOPSIS ./ping_linux.pl [-c --> count (Number of echo requests to be sent)] [-i --> interval (Interval in milliseconds between echo requests)] [-s --> packetsize (Size of icmp packet)] [-h --> destinationIP (Ip address of destination host)] [-w --> AllowableTime (Max time in seconds for sending receiving echo requests/reponse)]" =head1 DESCRIPTION This pings a host via the system ping command and returns RTA ,Tx packets,Rx packets,TTL,Packet-loss =cut use strict; use Getopt::Long; use Pod::Usage; my ($host,$count,$interval,$packetsize,$allowableTime); GetOptions( "h|host=s", \$host, "c|count=i", \$count, "i|interval=i", \$interval, "s|packetsize=i", \$packetsize, "w|allowableTime=i",\$allowableTime, ); #pod2usage("$0: No host given!\n") unless($host); pod2usage("$0:No host given!\n") unless($host && $host =~ /^((([2][5][0-5]|([2][0-4]|[1][0-9]|[0-9])?[0-9])\.){3})([2][5][0-5]|([2][0-4]|[1][0-9]|[0-9])?[0-9])$/); $count = 5 unless ($count); $interval = 1 unless ($interval); $packetsize = 56 unless ($packetsize); $allowableTime = 10 unless ($allowableTime); open CMD, "/bin/ping -c $count -i $interval -s $packetsize -w $allowableTime $host |" or die "Can't open ping: $!"; while () { my (@values1,@val1,@values2,@val2); if ( $_ =~ /PING/ ){ @values1 = split ; @val1 = split(/\(/,$values1[3]); $val1[1] =~ s/\)//; } print "$values1[1] \n"; print "$val1[0] \n"; if ($. == 2) { @values2 = split; @val2 = split(/\=/ , $values2[5]); } print "$val2[1] \n"; } close CMD