Category: | Miscellaneous |
Author/Contact Info | |
Description: | Convert long integers to dotted quad notation string. Convert dotted quad notation strings to long integer. A couple of quick functions I've been using to convert IP addresses. I seem to be using these quite often. Any and all comments/suggestions appreciated! Thanks to jdporter and ikegami who have shown me a better way. The code here is credited to ikegami. |
# thanks to jdporter and ikegami who have shown me a much better way t
+o do this!
#
# Thanks to ikegami for the code example
use Socket qw( inet_aton inet_ntoa );
sub DottedQuadToLong {
# Accepts triton.littlefish.ca
# Accepts 24.72.30.83
# Accepts 407379539
# etc
return unpack('N', inet_aton(shift));
}
sub LongToDottedQuad {
return inet_ntoa(pack('N', shift));
}
|
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: IP address - Converting between string and number
by ikegami (Patriarch) on Apr 28, 2006 at 20:10 UTC | |
by ruzam (Curate) on Apr 28, 2006 at 20:23 UTC | |
Re: IP address - long to dottedquad to long
by jdporter (Paladin) on Apr 28, 2006 at 20:06 UTC | |
Re: IP address - long to dottedquad to long
by davidrw (Prior) on Apr 28, 2006 at 20:20 UTC | |
by ruzam (Curate) on Apr 28, 2006 at 20:36 UTC |
Back to
Code Catacombs