This is my first ever program and I need some peer review on the code
and also have a few questions. I've read the Net::Ping documentation
and Learning Perl 4th edition.
use Net::Ping;
@host_array = ("4.4.4.4", "127.0.0.1", "123.333.333.333");
$p = Net::Ping->new("icmp");
foreach $host (@host_array) {
print "$host is dead\n" unless $p->ping($host, 2);
print "$host is alive.\n" if $p->ping($host);
}
$p->close();
- seems like I need to run the program as root or else I get an error:
"icmp ping requires root privilege at perl_ping.pl line 10" - is there
any way to fix this?
- what is the "2" in print "$host is dead\n" unless $p->ping($host,
2);?
- If I want to have IP addresses like: 1.1.1.0/8 or 203.10.22.19 to
203.10.22.255 is there any shortcut way to put this in the @array?
Thanks for any help.
-
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.