Skip to content

ntthanh2603/geoip-server

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

12 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

GeoIP Server

Daily Docker Build Docker Image Python FastAPI License

A lightweight FastAPI service that provides IP geolocation data using MaxMind's GeoLite2 databases.

✨ Features

  • 🌍 IP Geolocation Lookup - Detailed location data for any IP address
  • πŸ”„ Daily Auto Updates - GeoIP databases refreshed daily via GitHub Actions
  • 🐳 Docker Ready - Pre-built images on GitHub Container Registry
  • πŸš€ Fast API - Built with FastAPI for high performance
  • πŸ“Š Bulk Lookup - Query multiple IPs in a single request
  • πŸ“š Auto Documentation - Swagger UI and ReDoc included
  • πŸ”’ Type Safe - Full Pydantic validation

πŸš€ Quick Start

Using Docker (Recommended)

Pull and run the pre-built image from GitHub Container Registry:

docker pull ghcr.io/ntthanh2603/geoip-server:latest
docker run -p 4360:4360 ghcr.io/ntthanh2603/geoip-server:latest

Access the API at: http://localhost:4360

Using Docker Compose

git clone https://github.com/ntthanh2603/geoip-server.git
cd geoip-server
cp .env.example .env
# Edit .env with your MaxMind credentials
docker-compose up -d

πŸ“‘ API Endpoints

Endpoint Method Description Example
/ GET Get client's IP address curl http://localhost:4360/
/{ip} GET Lookup single IP curl http://localhost:4360/8.8.8.8
/bulk/{ips} GET Lookup multiple IPs curl http://localhost:4360/bulk/8.8.8.8,1.1.1.1
/docs GET Swagger UI documentation Open in browser
/redoc GET ReDoc documentation Open in browser

πŸ“„ Response Format

{
  "query": "8.8.8.8",
  "status": "success",
  "continent": "North America",
  "continentCode": "NA",
  "country": "United States",
  "countryCode": "US",
  "region": "CA",
  "regionName": "California",
  "city": "Mountain View",
  "district": "",
  "zip": "94035",
  "lat": 37.386,
  "lon": -122.0838,
  "timezone": "America/Los_Angeles",
  "offset": 5,
  "currency": "USD",
  "isp": "Google LLC",
  "org": "Google LLC",
  "as": "AS15169 Google LLC",
  "asname": "Google LLC"
}

πŸ› οΈ Development Setup

Prerequisites

Get a MaxMind license key (free):

Docker Development

# Build and run
docker-compose up --build

# Run in background
docker-compose up -d

# View logs
docker-compose logs -f

# Stop
docker-compose down

πŸ“¦ GitHub Container Registry

Pre-built Docker images with daily updated GeoIP databases are available at: ghcr.io/ntthanh2603/geoip-server

Available Tags

Tag Description Update Frequency
latest Latest stable build On every push to main
YYMMDD Daily snapshot Daily at 00:00 UTC
main-<sha> Specific commit On demand

Usage

# Latest version
docker pull ghcr.io/ntthanh2603/geoip-server:latest

# Specific date (e.g., Nov 2, 2025)
docker pull ghcr.io/ntthanh2603/geoip-server:251102

βš™οΈ GitHub Actions

Automated Workflows

Workflow Schedule Purpose
Daily Docker Build Daily at 00:00 UTC Update GeoIP databases & build images

Setup GitHub Actions

To enable automated builds:

  1. Navigate to: Settings β†’ Secrets and variables β†’ Actions
  2. Add repository secrets:
Name: GEOIPUPDATE_ACCOUNT_ID
Value: <your_maxmind_account_id>

Name: GEOIPUPDATE_LICENSE_KEY
Value: <your_maxmind_license_key>
  1. Go to Actions tab β†’ Select workflow β†’ Run workflow

The workflow will:

  • βœ… Verify secrets
  • βœ… Download latest GeoIP databases
  • βœ… Build Docker image
  • βœ… Push to GitHub Container Registry

πŸ“‚ Project Structure

geoip-server/
β”œβ”€β”€ .github/workflows/          # CI/CD workflows
β”‚   └── docker-build.yml        # Daily build automation
β”œβ”€β”€ src/
β”‚   β”œβ”€β”€ app.py                  # FastAPI application
β”‚   β”œβ”€β”€ configs/
β”‚   β”‚   └── path_database.py    # Database path config
β”‚   β”œβ”€β”€ controlers/
β”‚   β”‚   └── geoip_controler.py  # API endpoints
β”‚   β”œβ”€β”€ services/
β”‚   β”‚   └── geoip_service.py    # GeoIP lookup logic
β”‚   └── types/
β”‚       └── ip_geolocaltion.py  # Pydantic models
β”œβ”€β”€ main.py                     # Entry point
β”œβ”€β”€ Dockerfile                  # Docker configuration
β”œβ”€β”€ docker-compose.yml          # Compose configuration
β”œβ”€β”€ requirements.txt            # Python dependencies
└── .env.example                # Environment template

πŸ› οΈ Technologies

Technology Purpose
FastAPI Modern Python web framework
MaxMind GeoLite2 IP geolocation databases
Pydantic Data validation
Docker Containerization
GitHub Actions CI/CD automation

πŸ“ License

This project uses GeoLite2 data created by MaxMind, available from MaxMind.

🀝 Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

πŸ“§ Support


⭐ Star this repo if you find it useful!

Made with ❀️ using FastAPI and MaxMind GeoLite2

About

πŸ—ΊοΈ GeoIP Server is a lightweight service that provides IP geolocation data, using a Docker image automatically updated daily from MaxMind’s GeoLite2 database.

Resources

Stars

Watchers

Forks

Packages

 
 
 

Contributors