http://qs1969.pair.com?node_id=546367
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)); 
}