Skip to content

Instantly share code, notes, and snippets.

@acodega
Last active November 2, 2018 13:16
Show Gist options
  • Save acodega/489cd7e1a295bc2abce8cd3c60e2624c to your computer and use it in GitHub Desktop.
Save acodega/489cd7e1a295bc2abce8cd3c60e2624c to your computer and use it in GitHub Desktop.
#!/bin/sh
myIP=`curl -L -s --max-time 10 http://checkip.dyndns.org | egrep -o -m 1 '([[:digit:]]{1,3}\.){3}[[:digit:]]{1,3}'`
myLocationInfo=`curl -L -s --max-time 10 http://freegeoip.net/xml/$myIP`
myCountryCode=`echo $myLocationInfo|egrep -o '<CountryCode>.*</CountryCode>'| sed -e 's/^.*<CountryCode/<CountryCode/' | cut -f2 -d'>'| cut -f1 -d'<'`
myCity=`echo $myLocationInfo|egrep -o '<City>.*</City>'| sed -e 's/^.*<City/<City/' | cut -f2 -d'>'| cut -f1 -d'<'`
myRegionName=`echo $myLocationInfo|egrep -o '<RegionName>.*</RegionName>'| sed -e 's/^.*<RegionName/<RegionName/' | cut -f2 -d'>'| cut -f1 -d'<'`
echo "<result>$myCity, $myRegionName - $myCountryCode</result>"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment