[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
interger to I P address
- Subject: interger to I P address
- From: chartley at oar.net (chartley at oar.net)
- Date: Wed, 27 Aug 2008 13:00:41 -0400 (EDT)
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