Home Mac OS X Mac Terminal Lookup IP or Domain Geographical

Mac Terminal Lookup IP or Domain Geographical


From time-to-time I need to find the geographic location of any IP address or its domain name. It’s quickest for me to do this from the Mac Terminal. Here’s a shortcut you can set up to make it really easy to get the GEOIP data for a domain name or IP address.

In Terminal edit your ~/.bash_aliases file. E.g., nano ~/.bash_aliases

In the editor, add the following lines of code:

function geoip() {
        curl https://freegeoip.app/xml/$1

Save the file and exit the editor (e.g., in nano: ctrl-x, then y to save the file).
Use this command to load the modified file, source ~/.bash_aliases

Now you can look up the GeoIP data for a domain or IP address, with a command like this: geoip best-mac-tips.com, and you’ll see output like this:

$ geoip best-mac-tips.com 
<CountryName>United States</CountryName> 
<City>San Francisco</City> 


The command used above returns the results in and XML format. There are three other formats available, shown below.

Other Formats

The freegeoip.app service also supports CSV, JSON and JSONP.

For CSV, use the following in your bash file, curl https://freegeoip.app/csv/$1,US,United States,CA,California,San Francisco,94119,America/Los_Angeles,37.7794,-122.4176,807

For JSON, use this in your bash function, curl https://freegeoip.app/json/$1

{"ip":"","country_code":"US","country_name":"United States","region_code":"CA","region_name":"California","city":"San Francisco","zip_code":"94119","time_zone":"America/Los_Angeles","latitude":37.7794,"longitude":-122.4176,"metro_code":807}

Checking your own IP

You can check your own IP, using the new function, with the simple command, geoip.


No Comments

Leave A Reply

Please enter your comment!
Please enter your name here