Beefy Boxes and Bandwidth Generously Provided by pair Networks
XP is just a number
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??
#type 'perl scansub.pl' for help # #This program scans a C-class subnet and prints the results to corresp +onding text file. #If a computer has once answered the ping, it will not be added to the + list again. #To sort the output type 'perl scansub.pl sort <textfile>' use strict; use Net::Ping; my $host; my $subnet; my %state; my $h; my $time; my $if; my $of; my $line; if ($ARGV[0] eq 'sort'){ &sort; exit; } unless ($subnet=$ARGV[0]){ &usage; exit; } open OF,">>$subnet\.txt"; for $h(1 .. 255){ $host="$subnet\.$h"; $state{$host}='' } while(){ open OF,">>$subnet\.txt"; for $h(1 .. 254){ #sleep 2; $host="$subnet\.$h"; my $p=Net::Ping->new('icmp'); print "\nPinging host $host"; if ($p->ping($host,1)){ print " alive"; if ($state{$host} ne 'up'){ $time=localtime(); print OF "$host\twas up at $time\n"; $state{$host}='up'; } } } close OF; sleep 600 } sub usage{ print" This program scans a C-class subnet and lists all machines, that have answered ping, in a text file. Use this program to sort the output. Usage: perl scansub.pl <subnet> Example: perl scansub.pl 192.168.0 Sort: perl scansub.pl sort <file> Example: perl scansub.pl sort 192.168.0.txt "; } sub sort{ unless ($if=$ARGV[1]){ &usage; exit; } open IF,"$if" or die "Cannot open file $if for read: $!"; $of=">s.$if"; open OF,$of; my @data=<IF>; my @sorted=grep {s/(^|\D)0+(\d)/$1$2/g,1} sort grep {s/(\d+)/sprintf"%06.6d",$1/ge,1} @data; foreach $line(@sorted){ print OF $line; } close IF; close OF; exit; }

In reply to Scan C-Class for used IP-addresses by cab

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



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others wandering the Monastery: (4)
As of 2024-03-29 11:50 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found