Beefy Boxes and Bandwidth Generously Provided by pair Networks
No such thing as a small change
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??
Hi. I'm writing a little batch pinging utility that asks for the third octet and then scans the fourth from 1-255. I want the ping results to go to a log file, and then to scan that log file for a line containing "x bytes from 10.32.z.y" so that i know that ip is taken. The code is below. First though, I want to make sure my problems are clear: 1. It prints nothing to "ips.txt", even though ping fills out "log.txt" fine. 2. Styllistically, I want any suggestions to make the code more idiomatic.
---------------------------------------------------------------------- +----- #!/usr/bin/perl -w use strict; print "Please enter the third octet for scannin': "; my $octet3 = <>; chomp $octet3; open(LOG, ">log.txt") || die "Couldn't open log file: $! \n"; for(my $x = 0; $x < 20; $x++){ open(PINGIN, "ping 10.32.$octet3.$x -w 5 |") or die "Couldn't pull that one off: $! \n"; while(<PINGIN>){ warn "Logging activity for 10.32.$octet3.$x \n"; print LOG $_; } } close PINGIN; close LOG; open(LOG, "log.txt") or die "$!"; open(UNAVAILABLE, ">ips.txt") or die "$!"; while(my $line = <LOG>){ if($line =~ /^64 bytes from ([0-9.]):/){ my $ip = $1; print UNAVAILABLE "$ip is unavailable.\n"; } } close LOG; close AVAILABLE; --------------------------------------------------------------------
any help would be much appreciated. Thanks, Derek

In reply to batch ping problem by derek3000

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 about the Monastery: (6)
As of 2024-04-24 11:52 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found