North American Network Operators Group

Date Prev | Date Next | Date Index | Thread Index | Author Index | Historical

Re: interger to I P address

  • From: Izaac
  • Date: Wed Aug 27 17:07:53 2008

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


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