Skip to content

🌐 Self-hosted service for exposing IP information using MaxMind & GeoIP2 & Nginx that returns JSON/Plain data by IP.

License

Notifications You must be signed in to change notification settings

kraloveckey/whoip

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

3 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

🌐 whoip β€” Who is this IP?

Self-hosted solution to display IP information with Nginx, MaxMind and GeoIP2 databases.

This service returns plain text or JSON responses with IP address, geolocation, ASN, and user agent data β€” perfect for quick lookups or integrations.


πŸ”§ Requirements


πŸ“¦ GeoIP2 Database Setup

  1. Create a MaxMind account and generate a license key.

  2. Manually download databases:

$ wget "https://download.maxmind.com/app/geoip_download?license_key=YOUR_LICENSE_KEY&edition_id=GeoLite2-City&suffix=tar.gz"
$ wget "https://download.maxmind.com/app/geoip_download?license_key=YOUR_LICENSE_KEY&edition_id=GeoLite2-ASN&suffix=tar.gz"
$ wget "https://download.maxmind.com/app/geoip_download?license_key=YOUR_LICENSE_KEY&edition_id=GeoLite2-Country&suffix=tar.gz"

Or install geoipupdate for regular updates:

$ apt install geoipupdate

Configure it via /etc/GeoIP.conf, and add a cron job:

$ crontab -e

# Update every Tuesday at 02:00
0 2 * * 2 /usr/bin/geoipupdate

βš™οΈ Build Nginx with GeoIP2 module

$ cd /opt
$ git clone https://github.com/leev/ngx_http_geoip2_module.git
$ wget http://nginx.org/download/nginx-1.28.0.tar.gz
$ tar -xvf nginx-1.28.0.tar.gz
$ cd nginx-1.28.0/
$ apt install libmaxminddb0 libmaxminddb-dev mmdb-bin libpcre3 libpcre3-dev libssl-dev

$ ./configure --prefix=/etc/nginx --sbin-path=/usr/sbin/nginx --modules-path=/usr/lib/nginx/modules --conf-path=/etc/nginx/nginx.conf --error-log-path=/var/log/nginx/error.log --http-log-path=/var/log/nginx/access.log --pid-path=/var/run/nginx.pid --lock-path=/var/run/nginx.lock --http-client-body-temp-path=/var/cache/nginx/client_temp --http-proxy-temp-path=/var/cache/nginx/proxy_temp --http-fastcgi-temp-path=/var/cache/nginx/fastcgi_temp --http-uwsgi-temp-path=/var/cache/nginx/uwsgi_temp --http-scgi-temp-path=/var/cache/nginx/scgi_temp --user=nginx --group=nginx --with-compat --with-file-aio --with-threads --with-http_addition_module --with-http_auth_request_module --with-http_dav_module --with-http_flv_module --with-http_gunzip_module --with-http_gzip_static_module --with-http_mp4_module --with-http_random_index_module --with-http_realip_module --with-http_secure_link_module --with-http_slice_module --with-http_ssl_module --with-http_stub_status_module --with-http_sub_module --with-http_v2_module --with-http_v3_module --with-mail --with-mail_ssl_module --with-stream --with-stream_realip_module --with-stream_ssl_module --with-stream_ssl_preread_module --with-cc-opt='-g -O2 -ffile-prefix-map=/data/builder/debuild/nginx-1.26.2/debian/debuild-base/nginx-1.26.2=. -flto=auto -ffat-lto-objects -flto=auto -ffat-lto-objects -fstack-protector-strong -Wformat -Werror=format-security -Wp,-D_FORTIFY_SOURCE=2 -fPIC' --with-ld-opt='-Wl,-Bsymbolic-functions -flto=auto -ffat-lto-objects -flto=auto -Wl,-z,relro -Wl,-z,now -Wl,--as-needed -pie' --add-module=/opt/ngx_http_geoip2_module

$ make
$ make install

πŸ“ Nginx Configuration

Place the following files in your Nginx folder:

πŸ” API Endpoints

Endpoint Description
/ Client's IP address
/full Full info (IP, country, city, ASN, user agent)
/country Country name
/city City name
/city_location City longitude
/asn Autonomous system number
/as_desc ASN organization
/ua User agent
/json JSON with all available info
/build_epoch Build time of GeoIP databases

πŸ§ͺ Test

Start Nginx and curl one of the endpoints:

$ curl https://ip.dns.com/full

51.158.xx.xx
FR / France
Paris / 2.34940
AS12876 / Scaleway S.a.s.

curl/8.7.1

Example responses

$ curl ip.dns.com/json | jq .
{
  "ip": "51.158.xx.xx",
  "country_code": "FR",
  "country_name": "France",
  "city_name": "Paris",
  "city___cpLocation": "2.34940",
  "asn": "12876",
  "as_desc": "Scaleway S.a.s.",
  "user_agent": "curl/8.7.1"
}
$ curl ip.dns.com

51.158.xx.xx
$ ip.dns.com/ua

Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/137.0.0.0 Safari/537.36

Donate with PayPal

Releases

No releases published

Packages

No packages published