Skip to content

Instantly share code, notes, and snippets.

@liddiard
Last active September 14, 2015 18:35
Show Gist options
  • Save liddiard/912a4f3205e63d608873 to your computer and use it in GitHub Desktop.
Save liddiard/912a4f3205e63d608873 to your computer and use it in GitHub Desktop.
Bash script to show the current location of the machine you're running on using GeoIP in the format: "City, State, Country".
#!/bin/bash
API_URL="http://freegeoip.net/csv/"
# Get current external IP (http://askubuntu.com/a/95911)
IP=$(curl -s checkip.dyndns.org | sed -e 's/.*Current IP Address: //' -e 's/<.*$//')
LOCATION=$(curl -s ${API_URL}${IP})
echo "$LOCATION" | awk -F "," '{print $6 ",", $5 ",", $3}'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment