获取IP所处位置的Shell代码

2019年11月1日

这个脚本我忘记是哪个论坛里有朋友询问我就编写的演示代码了,好像是问全面禁止国外IP还是全面禁止国内IP了,PHP版本的同样道理,无非就是利用外部的api来查询某个IP的地理位置,至于怎么使用就靠自己去处理了。

Shell源码

# !/bin/bash
var=`curl https://pv.sohu.com/cityjson|sed 's/"//g'|sed -e 's/[ ][ ]*//g'`
cip=`echo $var|awk -F "," '{print $1}'|awk -F "cip:" '{print $2}'`
cid=`echo $var|awk -F ",cname" '{print $1}'|awk -F "cid:" '{print $2}'`
cnme=`echo $var|awk -F "};" '{print $1}'|awk -F "cname:" '{print $2}'`
echo $cip
echo $cid
echo $cnme

 


sicnature ---------------------------------------------------------------------
Your current IP address is: 18.209.209.28
Your IP address location: 美国弗吉尼亚阿什本
Your IP address country and region: 美国 美国
Your current browser is:
Your current system is:
Original content, please indicate the source:
同福客栈论坛 | 蟒蛇科普海南乡情论坛 | JiaYu Blog
sicnature ---------------------------------------------------------------------
Welcome to reprint. Please indicate the source http://www.myzhenai.com.cn/post/2917.html

没有评论

发表回复

您的电子邮箱地址不会被公开。 必填项已用*标注