[Shared] A shell script to get geo location of an IP address

less than 1 minute read

#!/bin/bash
locmessage=`curl -s ipinfo.io/$1`
city=`echo “$locmessage” | grep city | awk ‘{print $2}’ | sed ‘s/[s”,]//g’`
region=`echo “$locmessage” | grep region | awk ‘{print $2}’ | sed ‘s/[s”,]//g’`
country=`echo “$locmessage” | grep country | awk ‘{print $2}’ | sed ‘s/[s”,]//g’`
org=`echo “$locmessage” | grep org | awk ‘{$1=””; print $0}’ | sed ‘s/[s”,]//g’`
ip=`echo “$locmessage” | grep ip | awk ‘{print $2}’ | sed ‘s/[s”,]//g’`
echo “$ip($org[$city/$region/$country])”

 

Categories: Tech

Updated: