Shell调用curl实现IP归属地查询的脚本

可用于shell环境进行IP归属地查询

#!/bin/bash#传入IP参数IP=$1#使用百度开放地址库url="http://opendata.baidu.com/api.php?query=${IP}&co=&resource_id=6006&t=1412300361645&ie=utf8&oe=gbk&cb=op_aladdin_callback&format=json&tn=baidu&cb=jQuery1102026811896078288555_1412299994977&_=1412299994981"path=`curl -s $url |iconv -fgb2312 -t utf-8 |awk -F: '{ print $6}' |awk -F[\"] '{ print $2}'`echo "${IP}#${path}"

查询ip归属地的shell脚本 【Shell调用curl实现IP归属地查询的脚本】经常会遇到需要查找ip归属地,尤其是批量查找的时候,使用脚本就比较方便了,在网上找到一个,自己更改了一下,修复了在linux下出现中文乱码的问题,代码如下:
#!/bin/bash#Purpose: 查找ip地址所在地ipp (){exec < $1while read adosring=`curl -s "{a}&action=2"| iconv -f gb2312 -t utf-8|grep '' | awk -F '[<> ]+' '{print substr($7,7)}'`echo $a $sringdone}case $1 in-f)shiftipp $1; ; -i)shiftsring=`curl -s "{1}&action=2"| iconv -f gb2312 -t utf-8 |grep '' | 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

到此这篇关于Shell调用curl实现IP归属地查询的文章就介绍到这了,更多相关shell查询IP归属地内容请搜索脚本之家以前的文章或继续浏览下面的相关文章希望大家以后多多支持脚本之家!

    推荐阅读