nanog mailing list archives

Re: interger to I P address


From: Izaac <izaac () setec org>
Date: Wed, 27 Aug 2008 17:07:40 -0400

On Wed, Aug 27, 2008 at 05:50:44PM +0200, Andree Toonk wrote:
The Perl way:

sub ntoa_in_one_line { join(".", unpack("CCCC", pack("N", $_[0]))); }
print ntoa_in_one_line(1089055123) . "\n";

dec2ip
awk '{ print int($1 / 16777216) "." int($1 % 16777216 / 65536) "." int($1 % 65536 / 256) "." int($1 % 256) }'

ip2dec
awk '{ split($1, a, "."); print a[1]*16777216 + a[2]*65536 + a[3]*256 + a[4] }'


-- 
. ___ ___  .   .  ___
.  \    /  |\  |\ \
.  _\_ /__ |-\ |-\ \__


Current thread: