![]() |
|
more useful options | |
PerlMonks |
Re: IP Address Sanityby jdporter (Chancellor) |
on Nov 07, 2002 at 23:34 UTC ( #211290=note: print w/replies, xml ) | Need Help?? |
The problem with your general approach is that IP addresses aren't really textual strings, they're 32-bit integers. The dotted-quad is just one convenient representation. But it's not the only one. A proper solution to your stated need is to use the inet_aton and inet_ntoa functions provided by the Socket module, which is part of the standard library. inet_aton translates any valid IP address -- regardless of notation format -- or domain name into a packed string containing the 32-bit integer. Such a string can be converted into a dotted-quad representation by the inet_ntoa function. Example:
In Section
Seekers of Perl Wisdom
|
|