in reply to Using Net::Ping for broadcast address

A couple of thoughts...

If you have no idea which "$ThirdOctet's the servers are on, then I don't see where you would have any choice but to cycle through them all. Either give it a list of them directly (see below) or you if you can parse it from /etc/hosts, build it dynamically.
#! /usr/local/bin/perl -w use strict; use Net::Ping; my $IPBlk; my $FirstOctets = "10.0"; my @ValidOctets = (1, 5, 7); foreach my $ThirdOctet (@ValidOctets) { my $sbnt = "$FirstOctets." . "$ThirdOctet" . ".0"; print "Pinging: $sbnt\n"; my $p = Net::Ping->new(); if ($p->ping("$sbnt") ) { print "host exists\n"; } else { print "Host does not exist\n"; } print "$?\n"; }
If you can parse /etc/hosts it might pay to put a distinguishing comment on the lines that are servers (### SERVER ###). You could then parse the file for these entries and build a list of known servers to ping via their direct address. Don't know it this is exactly what you are looking to accomplish, but you might want to try that approach instead. Might take some work to fix up your /etc/hosts file, but it would be a one-timer.

-THRAK
www.polarlava.com

Replies are listed 'Best First'.
Re: Re: Using Net::Ping for broadcast address
by birdbrane (Chaplain) on Mar 30, 2001 at 22:48 UTC
    Hey THRAK,

    Thanks for the reply. Actually, I don't necessarily know which subnet ($ThirdOctet) the systems are on. Part of this script is to "auto-discover". By replacing Net::Ping w/ `/usr/sbin/ping `$sbnt`, I can scan the broadcast address, just look for the word /alive/ and it hums happily along.

    I have a working script, but I am just a little bummed that I can't get perl's ping to do job. In other words: why won't perl's ping allow/recognize a broadcast address ping response?

    Joe

      Joe, Are you running this as yourself or root? ICPM only works as root. Read the "Description" section here. I haven't used Net::Ping much, but I did play around with it a bit while trying to build a monitor for a bunch of distributed check printers.

      -THRAK
      www.polarlava.com
        Inter-Continental-Perlish-Missile ??
            /me ducks,
            Don