#!/bin/bash
a=$1
N=$a
L2=$((($N & 0x000000ff) ))
L1=$((($N & 0x0000ff00) >> 8))
H2=$((($N & 0x00ff0000) >> 16))
H1=$((($N & 0xff000000) >> 24))
echo $a " " $L2.$L1.$H2.$H1
./Num-To-Ip20150716.sh 数字IP
#!/bin/bash
for a in `cat ./20150427-num-ip.txt`
do
N=$a
L2=$((($N & 0x000000ff) ))
L1=$((($N & 0x0000ff00) >> 8))
H2=$((($N & 0x00ff0000) >> 16))
H1=$((($N & 0xff000000) >> 24))
echo $a " " $L2.$L1.$H2.$H1 >> ./20150427-IP.txt
done
txt文档里面是数字IP
老大写的一个shell转换IP的 很好用 ,分享下!
#!/bin/bash
hexip=""
hextoip() {
hex=$1
ip1=`printf "%d." 0x${hex:6:2}`
ip2=`printf "%d." 0x${hex:4:2}`
ip3=`printf "%d." 0x${hex:2:2}`
ip4=`printf "%d" 0x${hex:0:2}`
ip=$ip1$ip2$ip3$ip4
hexip=$ip
#return $ip
}
iptohex() {
IFS=.
for str in $1
do
printf "%02X" $str
done
}
iptoaddr ()
{
#exec < $1
#while read a
for a in `cat $1`
do
#sring=`curl -s "{a}&action=2" |grep '
-
' |awk -F'[><]+' '{print $5}'`
#sring=$(wget -q "{a}&action=2" -O -| iconv -f gbk -t utf-8 | grep "数据" | awk -F"ul" '{print $3}' | awk -F"" '{print $1$2}' | awk -F"" '{print $2"\n"$3}' | head -1)
hex=`printf "%X" ${a}`
#echo $a $hex
hextoip $hex
#hexip=$?
#echo $a $hexip
sring=$(wget -q "{hexip}&action=2" -O -| grep '
-
' |awk -F'[><]+' '{print $5}')
echo $a $hexip $sring
done
}
case $1 in
-f)
shift
iptoaddr $1
;;
-i)
shift
#sring=`curl -s "{1}&action=2" |grep '
-
' |awk -F'[><]+' '{print $5}'`
#sring=$(wget -q "{1}&action=2" -O -| iconv -f gbk -t utf-8 | grep "数据" | awk -F"ul" '{print $3}' | awk -F"" '{print $1$2}' | awk -F"" '{print $2"\n"$3}' | head -1)
#sring=$(wget -q "{1}&action=2" -O -| grep "数据" | awk -F"ul" '{print $3}' | awk -F"" '{print $1$2}' | awk -F"" '{print $2"\n"$3}' | head -1)
sring=$(wget -q "{1}&action=2" -O -| grep '
-
' |awk -F'[><]+' '{print $5}')
echo $1 $sring
;;
-h)
shift
hex=`echo "ibase=10;obase=16;$1"|bc`
echo $hex
hextoip $hex
;;
-x)
shift
iptohex $1
;;
*)
echo "[Help]
$0 need -f or -i
-f ------- argument is a file
-i ------- argument is a IP
[For example]:
$0 -f filename
$0 -i ipadress
"
;;
esac
阅读(1353) | 评论(0) | 转发(0) |