Greets,

I am trying to right a series of scripts to map out all of our *nix hosts on our intranet, in order to ease administration. One part of that script requires that I ping each address. Problem is, if the subnet doesn't exist, I don't want to ping 255 addresses only to find nothing.

I wrote a perl script to ping the broadcast address (using Net::Ping) but it comes back that the address doesn't exist (even though a command line ping does).

Am I doing something incorrectly here, or does Net::Ping not work for pinging broadcast addresses? I have tried w/ and w/o ICMP, again, to no avail.

For information purposes, here is the script:

#! /usr/local/bin/perl -w use strict; use Net::Ping; my $IPBlk; my $FirstOctets = "10.0"; my $ThirdOctet; for ($ThirdOctet = 1; $ThirdOctet <= 25; $ThirdOctet++) { $IPBlk = "$FirstOctets." . "$ThirdOctet"; my $sbnt = "$IPBlk" . ".0"; my $p = Net::Ping->new(); if ($p->ping("$sbnt") ) { print "host exists\n"; } else { print "Host does not exist\n"; } print "$?\n"; }

Many thanks in advance,

Joe


In reply to Using Net::Ping for broadcast address by birdbrane

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.