shell转换IP
来源:互联网 发布:private java中的作用 编辑:程序博客网 时间:2024/06/16 14:49
老大写的一个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 "http://ip138.com/ips138.asp?ip=${a}&action=2" |grep '<ul class="ul1"><li>' |awk -F'[><]+' '{print $5}'`
#sring=$(wget -q "http://www.ip138.com/ips.asp?ip=${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 "http://ip138.com/ips138.asp?ip=${hexip}&action=2" -O -| grep '<ul class="ul1"><li>' |awk -F'[><]+' '{print $5}')
echo $a $hexip $sring
done
}
case $1 in
-f)
shift
iptoaddr $1
;;
-i)
shift
#sring=`curl -s "http://ip138.com/ips138.asp?ip=${1}&action=2" |grep '<ul class="ul1"><li>' |awk -F'[><]+' '{print $5}'`
#sring=$(wget -q "http://ip138.com/ips138.asp?ip=${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 "http://ip138.com/ips138.asp?ip=${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 "http://ip138.com/ips138.asp?ip=${1}&action=2" -O -| grep '<ul class="ul1"><li>' |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
- shell转换IP
- shell数字转换成IP
- 汇总下几个IP计算/转换的shell小脚本
- shell脚本:ip/mask 转换为 ip1-ip2
- IP转换
- sed c\命令,IP地址和16进制数互相转换等一些精彩shell代码
- 用Shell脚本对IP的字符串与整数形式进行相互转换
- IP校验shell脚本
- shell ip扫描
- shell检查IP是否合法
- shell ip 排序
- shell检查IP合法性
- shell: ip合法性检查
- shell获取IP地址
- shell 获取主机ip
- unix shell获取IP和修改IP
- IP到数字转换
- 域名转换IP
- poj3468(A Simple Problem with Integers)线段树实现
- 【图文笔记】初识uGUI(四)
- 05关于两种context的区别
- poj3683 pascal题解
- 多媒体基础学习
- shell转换IP
- Hduoj3068【manacher算法】
- xshell 如何添加快捷方式
- 使用Part上传附件
- 第十四周OJ项目——杨辉三角
- poj 3468线段树 成段更新
- Codeforces Round #279 (Div. 2)
- Block简单四种
- 常去网站记录