#!/usr/bin/perl -w use String::Util 'trim'; =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,$p); 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 = 64 unless ($packetsize); $allowableTime = 1 unless ($allowableTime); #print "\$count is : $count \n"; open CMD, "/bin/ping -c $count -i $interval -s $packetsize -w $allowableTime $host |" or die "Can't open ping: $!"; while () { print "$_ "; } close CMD;