您的位置:首页 > 运维架构 > Shell

查询ip归属地的shell脚本

2012-06-13 17:44 232 查看
经常会遇到需要查找ip归属地,尤其是批量查找的时候,使用脚本就比较方便了,在网上找到一个,自己更改了一下,修复了在linux下出现中文乱码的问题,代码如下:

点击(此处)折叠或打开

#!/bin/bash
#Purpose: 查找ip地址所在地
ipp (){
exec < $1
while read a
do
sring=`curl -s "http://ip138.com/ips138.asp?ip=${a}&action=2"| iconv -f gb2312 -t utf-8|grep '<ul class="ul1"><li>' | awk -F '[<> ]+' '{print substr($7
,7)}'`
echo $a $sring
done
}
case $1 in
-f)
shift
ipp $1
;;
-i)
shift
sring=`curl -s "http://ip138.com/ips138.asp?ip=${1}&action=2"| iconv -f gb2312 -t utf-8 |grep '<ul class="ul1"><li>' | awk -F '[<> ]+' '{print substr($7,7)}'`
echo $1 $sring
;;
*)
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
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: