Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: Regexp: Private IP Addresses
by ikegami (Patriarch) on Aug 25, 2009 at 19:25 UTC | |
One often works with IP addresses in packed form which allows for a very efficient regex match:
Test:
Update: Alternatives:
| [reply] [d/l] [select] |
by markkawika (Monk) on Aug 26, 2009 at 21:20 UTC | |
| [reply] |
by ikegami (Patriarch) on Aug 26, 2009 at 21:49 UTC | |
No. There are similarities between all the solutions provided in this discussion (including between mine and that module's), but the module's solution is far from being exactly the same as any of mine. According to the docs, it uses the binary representation of the address (a long string of zeros and ones), whereas all of my solutions work with the address as a native number (C long). That makes some of them byte-oriented and some of them mask-oriented, but none are bit-oriented like that module. Mind you, any of the solutions in this discussion could be given the same interface as that module. | [reply] |
Re: Regexp: Private IP Addresses
by markkawika (Monk) on Aug 25, 2009 at 18:22 UTC | |
You can use Net::IP::Match::Regexp to do this:
| [reply] [d/l] |
by Sewi (Friar) on Aug 25, 2009 at 18:36 UTC | |
If you got it from a non-network input (like a user form), don't trust in it, it may be 10.9999.1234.666. | [reply] [d/l] |
by andreas1234567 (Vicar) on Aug 26, 2009 at 08:29 UTC | |
-- No matter how great and destructive your problems may seem now, remember, you've probably only seen the tip of them. [1] | [reply] [d/l] |