Locate IP Address by City on Fedora 25

17 Oct 2017

This document describes how to locate the location of an IP Address by city on Fedora 25.

If you are using another system then you will need to use another package manager to install GeoIP, however the other shell commands should work if /usr/share/GeoIP is populated (otherwise you will need to find the location of these .dat files on your own).

Install data and tool:

sudo dnf install -y GeoIP GeoLite-data-extra

In a shell run:

ip="$(curl ifconfig.co)"
geoiplookup -f /usr/share/GeoIP/GeoIPCity.dat "$ip"
GeoIP City Edition, Rev 1: US, CO, Colorado, Colorado Springs, 80918, 38.914200, -104.774902, 752, 719

These lines of shell code do the following

  1. Retrieve your internet facing IP by issuing a HTTP GET request to ifconfig.co
  2. Use geoiplookup IP address lookup based on the geoip package database. Explicitly refer to GeoIPCity.dat otherwise the result will only be country specific instead of city specific

Comments !