Skip to content

Instantly share code, notes, and snippets.

@benzBrake
Created November 23, 2016 06:37
Show Gist options
  • Save benzBrake/d2fda8dfe6e7551aa6e656f7b7edf617 to your computer and use it in GitHub Desktop.
Save benzBrake/d2fda8dfe6e7551aa6e656f7b7edf617 to your computer and use it in GitHub Desktop.
Get IP Location (Data Source: IPIP)
#/bin/sh
ip=$1
echo ${ip}|grep "^[0-9]\{1,3\}\.\([0-9]\{1,3\}\.\)\{2\}[0-9]\{1,3\}$" > /dev/null;
if [ $? -eq 0 ]
then
result=`curl "http://ip.huomao.com/ip?ip=${ip}" 2>/dev/null`
result=${result:1:(-1)}
country=`echo ${result} | awk -F, '{ print $1}' | awk -F: '{ print $2}'`
province=`echo ${result} | awk -F, '{ print $2}' | awk -F: '{ print $2}'`
city=`echo ${result} | awk -F, '{ print $3}' | awk -F: '{ print $2}'`
isp=`echo ${result} | awk -F, '{ print $4}' | awk -F: '{ print $2}'`
echo ${country:1:(-1)} ${province:1:(-1)} ${city:1:(-1)} ${isp:1:(-1)}
else
echo 'null'
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment