Is it possible to get the geolocation of an IP address in Terminal?

Not sure what the numbers in an IP address mean, but there must be some logic behind it, so lookup can't be that hard.


3 Answers 3


You can do this without having to install any additional apps or software. Just use the command curl and the free geo ip website http://freegeoip.app.

Execute the following command in Terminal (I am using Apple's IP for this example):

curl https://freegeoip.app/xml/

You will get your results in an XML format:

    <CountryName>United States</CountryName>

You can even issue the same command using the domain name instead of the IP:

curl https://freegeoip.app/xml/apple.com

Other Formats...

freegeoip.app also supports CSV, JSON and JSONP

CSV: curl https://freegeoip.app/csv/apple.com,US,United States,CA,California,Cupertino,95014,America/Los_Angeles,37.30,-122.09,807

JSON: curl https://freegeoip.app/json/apple.com

{"ip":"","country_code":"US","country_name":"United States","region_code":"CA","region_name":"California","city":"Cupertino","zip_code":"95014","time_zone":"America/Los_Angeles","latitude":37.3042,"longitude":-122.0946,"metro_code":807}

To check your own ip...

Just omit the ip or domain:

curl https://freegeoip.app/xml/

  • 10
    NOTE: linking an IP address to a geographical location is not a hard science. While most addresses will be reliable, there are millions of addresses that, when looked up, will resolve to a general location, like the center of a city, or even the middle of the country. There is an interesting article about how an random farm in the middle of Kansas has been the target of abuse and criminal investigations because a major geolocation service placed their "general location for the USA" flag on their farm. fusion.net/story/287592/internet-mapping-glitch-kansas-farm is a link to the article.
    – Nzall
    Commented May 3, 2016 at 13:12
  • 2
    This API endpoint is deprecated and will stop working on July 1st, 2018. For more information please visit: github.com/apilayer/freegeoip#readme</DeprecationMessage>
    – 0n1cOn3
    Commented Jun 28, 2018 at 8:55
  • 2
    looks like the new "freegeoip.app" works as expected. "freegeoip.net" was deprecated
    – dwightk
    Commented Feb 13, 2019 at 12:10
  • @Allan curl https://freegeoip.app/xml/ does not show IPv4
    – SebMa
    Commented Apr 30, 2020 at 9:49
  • @SebMa - Just tested it. Works as described.
    – Allan
    Commented Apr 30, 2020 at 12:24

Use https://github.com/maxmind/mmdbinspect with databases from https://github.com/wp-statistics/GeoLite2-City:

mmdbinspect -db "$database_file" "$ip"

You can use jq to further process the output.


There is a small and compact command line tool called gip, written in C++, available at https://github.com/softhub-software-development/gip.


# gip softhub.com "Berlin, Berlin, Germany"

# gip "Berlin, Berlin, Germany"

# gip -t google.com "Berlin, Berlin, Germany" "Eschborn, Hessen, Germany" "Mountain View, California, United States"

# gip -g softhub.com
52.5244 13.4105

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .