[lug] Perl 101
Terry Branaman
t-branaman at attbi.com
Thu Apr 18 21:15:43 MDT 2002
On Thu, 2002-04-18 at 15:24, John Karns wrote:
> I'm just beginning to dig into Perl a bit to learn enough to write
> implement some rudimentary scripts. For starters, using O'Reilly's
> Perl Bookshelf CD as a reference and learning source, I have:
>
> #---------------------- cut --------------------------
> #!/usr/bin/perl
>
> use Net::Ping;
>
> $hostname = "192.168.1.108";
> $timeout = 50;
>
> if (pingecho($hostname, $timeout)) {
> print "host is alive\n";
> }
> exit ;
>
> #---------------------- cut --------------------------
>
> which is an example from the CD and fails, although I can see the lights
> flash on the destination machine's NIC when I run the script. Command
> line pings also work fine. The text from the CD says that there is no
> guarantee that the call will succeed but as I said, it does seem to doing
> the probe. I've tried it without the optional timeout parm as well with
> identical results. So I'm wondering if it's a configuration issue or
> something else. The idea is to have a script on my laptop that will
> detect which LAN it's connected to, and do various tasks based on that.
>
> Is there an alternative method that might be preferred to my approach?
> Any suggestions greatly appreciated!
>
> ----------------------------------------------------------------
> John Karns jkarns at csd.net
>
> _______________________________________________
> Web Page: http://lug.boulder.co.us
> Mailing List: http://lists.lug.boulder.co.us/mailman/listinfo/lug
I found another script in the man pages (which I had to use the -M option to read):
use Net::Ping;
$p = Net::Ping->new();
print "$host is alive.\n" if $p->ping($host);
$p->close();
However, this didn't work for me either except with the icmp protocol:
$p = Net::Ping->new("icmp");
I hope that this helps.
Terry Branaman
More information about the LUG
mailing list