• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1505
  • Last Modified:

Ping Perl Script

How to write a script to :

1)Ping Local Machine

2)Ping Remote Machine


0
gauravflame
Asked:
gauravflame
  • 4
  • 4
  • 2
  • +1
1 Solution
 
ozoCommented:
perl -MNet::Ping -e "print'host is alive' if pingecho shift" 127.0.0.1

perl -MNet::Ping -e '$p= Net::Ping->new("icmp");print"host is alive\n" if $p->ping(shift)' www.experts-exchange.com
0
 
gauravflameAuthor Commented:
I write the code in the notepad , name as "ping.pl" .
Try to execute through "perl -w ping.pl" under Window Command Shell(cmd)

But I get error MNet::Ping package not Found

From where to get packages of Perl. I install only Perl5.6 in my WindowXP system.
 

 
0
 
ozoCommented:
The above were commands to type at the shell, (like  "perl -w ping.pl")
If you want to put it into ping.pl it would look more like

use Net::Ping;
$p= Net::Ping->new("icmp");
print "host is alive\n" if $p->ping("127.0.0.1");
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
ozoCommented:
if Net::Ping is not installed, try "ppm install Net::Ping" under Window Command Shell
0
 
gauravflameAuthor Commented:
Unable to install "ppm install Net::Ping"

Do I have to install CPAN Window version on my machine.So I will get CPAN perl modules or there is another way.

0
 
Adam314Commented:
At command promt: Type  "ppm"

at ppm> prompt, type "search net-ping"
You should get this response:
  1. Net-Ping-External [0.11] Net-Ping-External

at ppm> prompt, type "install 1"
**it will install the package**

at ppm> prompt, type "quit"
0
 
gauravflameAuthor Commented:
Again Unable to install

Everything went fine except Last step

At command promt: Type  "ppm"  (OK)

at ppm> prompt, type "search net-ping" (OK)
You should get this response:
  1. Net-Ping-External [0.11] Net-Ping-External(OK)
==========ERROR=================================
at ppm> prompt, type "install 1"(OK) after this error message
**it will install the package**
Error Message :  Could Not Locate PDF file for Package 1
==============================================

at ppm> prompt, type "quit"(OK)
0
 
Adam314Commented:
I didn't get that error... did it install anyway?   Put this in a file, and try to run it:


#!/usr/bin/perl
use strict;
use Net::Ping;
0
 
tone28Commented:
What version of Perl are you using?

perl -v

Otherwise if you are using Windows here is a version you can try that just uses command shell ping.



PingComp("localhost");
PingComp("10.65.69.50");

sub PingComp {
    my($comp) = shift;
   
    my $result = `ping -n 1 localhost`;
    if($result =~ m/Reply.from/) {
        print "$comp is live on the network\n";
      }
    else {
        print "$comp is NOT live on the network\n";
    }
}
0
 
gauravflameAuthor Commented:
By using "perl -v" on command shell of Window Xp

I get 5.6.1 version of Perl

I am not able to install the Net::Ping in my system .I get error.


Yes your last script works ,I mean PingComp().

But I need the output just exactly like the TCP/IP tool ping command on cmd shell.
l

0
 
ozoCommented:
system 'ping -n 1 localhost';
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

  • 4
  • 4
  • 2
  • +1
Tackle projects and never again get stuck behind a technical roadblock.
Join Now