#!/usr/bin/perl use Net::Ping; use Socket; #********************************************************************* # pinger : Ping C-Class Ip's in the following subnets (@subnets) # # Description: ping hosts in the listed subnets and report to STDOUT # # Modified an existing pid fork ping script written by Randal Scwartz # Octet range listed is set for my building removed # broadcast octets as well as unused hosts in low range. # # Donald J. Reckinger Mon Aug 5 15:57:04 EDT 2002 #********************************************************************* @subnets = (1,2,3,4,5,6,7); foreach $subnet (@subnets) { for ($octet=20; $octet <= 254; $octet++) { push @hosts, "192.168.$subnet.$octet"; } } sub ping_a_host { $p = Net::Ping->new("icmp"); ($p->ping($host,2)) =~ /1/ ? 1 : 0; $p->close(); } my %pid_to_host; my %host_result; sub wait_for_a_kid { $p = Net::Ping->new("icmp"); my $pid = wait; return 0 if $pid < 0; my $host = delete $pid_to_host{$pid} or warn("Why did I see $pid ($?)\n"), next; warn "stopping $pid for $host\n"; $host_result{$host} = ($p->ping($host,2)) =~ /1/ ? 1 : 0; 1; } for (@hosts) { wait_for_a_kid() if keys %pid_to_host > 10; if (my $pid = fork) { ## parent does... $pid_to_host{$pid} = $_; warn "$pid is processing $_\n"; } else { # child does ## child does... exit !ping_a_host($_); } } ## final reap: 1 while wait_for_a_kid(); for (sort keys %host_result) { chomp(my $claimed_hostname = gethostbyaddr(inet_aton($_ ),AF_INET)); print "$_ aka $claimed_hostname is ", ($host_result{$_} ? "good" : "ba +d"), "\n"; }

In reply to Scan C Subnets for /up/down hosts and resolve names in DNS by /dev/null

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.