interger to I P address

chartley at chartley at
Wed Aug 27 12:00:41 CDT 2008

Sorry to be continuing this thread, but I find a certain kind of elegance in
bash which isn't actually there, but helps me sleep at night.

bash# iptoint(){ oct1=`echo $1|awk -F\. '{print $1}'`; oct2=`echo $1|awk -F\. '{print $2}'`; oct3=`echo $1|awk -F\. '{print $3}'`; oct4=`echo $1|awk -F\. '{print $4}'`; echo $[($oct1<<24)+($oct2<<16 )+($oct3<<8)+$oct4 ];}
bash# inttoip(){ echo $[$1>>24].$[($1>>16)&255].$[($1>>8)&255].$[$1&255]; }

bash# inttoip 1089055123
bash# iptoint


More information about the NANOG mailing list