I think you misunderstood me (and read my flawed code for help), because what I meant was that 0 and 255 are *NOT* valid values for a *host* in the last octet, but you're right, they're valid anywhere else (except of course, a 0 in the first octet unless you're using all-zeros broadcast, which is non-standard by modern convention, or a 255 in the first octet, which is valid only for broadcast addresses). But that's pedantic.
If you want to do a complete test, the NetAddr::IP module from CPAN (or just use the trick of trying to open a socket with the address and see if it works).
But I did make a mistake; the regexp I wrote does needs to account for 0's in the last octet, provided that the last octet does not contain *only* zeros. So a more correct version would be this, if you wanted to ONLY verify *HOST* addresses and not broadcasts or subnets (please note: the regexp below does not prohibit '255' values in the first or last octet, which are technically invalid for *host* addresses):
unless ($get
&& $get =~ /^[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[1-9][0-9]{0,
+2}$/
&& !grep { $_ < 0 || $_ > 255 } split(/\./, $get) )
{ print "BAFFLING: invalid target specified\n"; exit(-
+1);}
Signature void where prohibited by law.
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.