Dear Monks,

Please enlighten me about Net::Ping.

Here's my script:
#!/usr/bin/perl -w use strict; use Net::Ping; use Getopt::Std; my $protocal = "icmp"; my $network = "user must enter"; my $start = 0; my $end = 255; my $timeOut = 1; use vars qw/ $opt_p $opt_N $opt_S $opt_E $opt_T $opt_h/; getopt( "p:N:S:E:T:h" ); if( $opt_p ) {$protocal = $opt_p;} if( $opt_N ) {$network = $opt_N} else { &usage(); exit(); } if( $opt_S ) {$start = $opt_S} if( $opt_E ) {$end = $opt_E} if( $opt_T ) {$timeOut = $opt_T} if( $opt_h ) {&useage(); exit();} my $p = Net::Ping->new($protocal,$timeOut); for(my $node=$start; $node<$end; $node++){ my $address = "$network.$node"; print $address,($p->ping($address) ? ' is alive' : ' is not alive' +),"\n"; } $p->close(); sub usage { print<<DOIT; $0 -N<network> [-p<protocal>][-S<start>][-E<end>][-T<timeout>][-h] network actually first 3 octects of an IP address protocal can be icmp, tcp or udp default is icmp start default 0 end default 255 timeout default 1 DOIT }

I have been executing it on a NT system from a cygwin bash
shell (if that makes a difference)

Here's the output from various runs of the script:
$ ./ping.pl -N 123.321.12 -ptcp 123.321.12.0 is not alive 123.321.12.1 is not alive ^C // script seemed to hang $ ./ping.pl -N 123.321.12 -pudp 123.321.12.0 is not alive 123.321.12.1 is not alive 123.321.12.2 is not alive 123.321.12.3 is not alive 123.321.12.4 is not alive 123.321.12.5 is not alive 123.321.12.6 is not alive 123.321.12.7 is not alive ... 123.321.12.254 is not alive $ ./ping.pl -N 123.321.12 icmp ping requires root privilege at ./ping.pl line 21

My questions:

1) Why did ping.pl -N 123.321.12 -ptcp hang?
2) Why didn't ping.pl -N 123.321.12 -pudp not ping anything?
3) Why did ping.pl -N 123.321.12 get that error message?

I don't know much ... about networks :)

In reply to Why does Net::Ping behave this way? by rbc

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.