By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
437,903 Members | 1,086 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 437,903 IT Pros & Developers. It's quick & easy.

Help on Network machine's status using ping command.

P: 16
Can any one help me on ping command .
Expand|Select|Wrap|Line Numbers
  1. for this line of code 
  2. ($ret, $duration, $ip) = $p->ping ($line)
  3.  
If i give any
1> invalid entry as a parameter ($line) in ping command

or

2>Any network machine's name that actualy exists but it is down


it is returning same value for ($ret, $duration, $ip) in both the cases .


.................................................. ....
The actual scripts to use this..
Expand|Select|Wrap|Line Numbers
  1. use Net::Ping;
  2. use Time::HiRes;
  3.  
  4. use strict;
  5.  
  6. my $interval = 5;
  7. print "\n\nEnter any path of a filename : \t";
  8. my $pth = <STDIN>;
  9. chomp $pth;
  10. $pth =~ tr#\\#/#;
  11. print "\n\nEnter any path of a filename to store the result : \t";
  12. my $pt = <STDIN>;
  13. chomp $pt;
  14. $pt =~ tr#\\#/#;
  15. #print $pth;
  16. open(FILE, "$pth") or die "Can't open $pth : $!";
  17. open(fl,">$pt") || die "Can't open $pt : $!";
  18. while (<FILE>) {
  19.     chomp;
  20.         my $line = $_;
  21.     my $p = Net::Ping->new("icmp", $interval);
  22.     my ($ret, $duration, $ip) = $p->ping ($line);
  23.  
  24.  
  25.     if ($ret) {
  26.         printf fl " \n \n $line 's address is $ip and it is up %.2f\n", 1000 * $duration;
  27.         } else {
  28.         print fl "$line down 0.00\n";
  29.         }
  30.  
  31.     }
  32.     close FILE;
  33.                 close fl;
  34.  
Can any one suggest me to manipulate that script so that it can show different proper message for the above stated two scenarios.
!!

advance thanx for any one to help on this..
Nov 17 '08 #1
Share this Question
Share on Google+
1 Reply


Icecrack
Expert 100+
P: 174
First Please use code tags as the Moderator has said,

Second, Please explain a little more, i don't understand what you want exactly

and another thing Have you attempted this on your own?


Kind Regards

Charlie
Nov 19 '08 #2

Post your reply

Sign in to post your reply or Sign up for a free account.