[107183] in North American Network Operators' Group

home help back first fref pref prev next nref lref last post

Re: interger to I P address

daemon@ATHENA.MIT.EDU (Izaac)
Wed Aug 27 17:07:57 2008

Date: Wed, 27 Aug 2008 17:07:40 -0400
From: Izaac <izaac@setec.org>
To: nanog@nanog.org
In-Reply-To: <20080827155044.GB24576@toonk.nl>
Reply-To: Izaac <izaac@setec.org>
Errors-To: nanog-bounces@nanog.org

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] }'


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


home help back first fref pref prev next nref lref last post