interger to I P address

chartley at oar.net chartley at oar.net
Wed Aug 27 17:00:41 UTC 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
64.233.169.147
bash# iptoint 64.233.169.147
1089055123

Chris





More information about the NANOG mailing list