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
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: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.