Sign inSign up

ytzcom/geoip-updater

By ytzcom

•Updated 2 days ago

GeoIP database updater with support for MaxMind and IP2Location

Buildkit cache
Image
0

10K+

ytzcom/geoip-updater repository overview

⁠Python CLI

Full-featured Python client for GeoIP database updates with async downloads, configuration files, and advanced features.

⁠✨ Key Features

  • 🚀 Async Downloads: Concurrent downloads for maximum speed
  • 📁 Config Files: YAML configuration support for complex setups
  • 🔄 Smart Retry: Exponential backoff with jitter
  • 📊 Progress Bars: Real-time download progress
  • 🔐 Secure: Input validation and safe file handling
  • 🐳 Docker Ready: Multi-platform container support

⁠🚀 Quick Start

⁠Docker Run
# Simple download
docker run --rm \
  -e GEOIP_API_KEY=your-key \
  -v $(pwd)/data:/data \
  ytzcom/geoip-updater:latest

# With specific databases
docker run --rm \
  -e GEOIP_API_KEY=your-key \
  -e GEOIP_DATABASES="city,country" \
  -v $(pwd)/data:/data \
  ytzcom/geoip-updater:latest
⁠Native Installation
# Install dependencies
pip install aiohttp pyyaml tqdm

# Download script
curl -O https://raw.githubusercontent.com/ytzcom/geoip/main/cli/python/geoip-update.py
chmod +x geoip-update.py

# Run
./geoip-update.py --api-key your-key

⁠🔧 Configuration

⁠Environment Variables
VariableDefaultDescription
GEOIP_API_KEY(required)Your authentication API key
GEOIP_API_ENDPOINThttps://geoipdb.net/authAPI endpoint URL
GEOIP_TARGET_DIR/dataDatabase storage directory
GEOIP_DATABASESallDatabases to download
GEOIP_CONFIG_FILE-Path to configuration file
GEOIP_LOG_FILE-Log file path
⁠Configuration File

Create config.yaml for advanced setups:

# Authentication
api_key: "your-api-key-here"
api_endpoint: "https://geoipdb.net/auth"

# Storage
target_dir: "/var/lib/geoip"
temp_dir: "/tmp/geoip"

# Database selection
databases:
  - "GeoIP2-City.mmdb"
  - "GeoIP2-Country.mmdb"
  - "GeoIP2-ISP.mmdb"

# Performance
max_concurrent: 6
chunk_size: 8192
timeout: 300

# Retry logic
max_retries: 3
retry_delay: 2.0
retry_multiplier: 2.0

# Logging
log_file: "/var/log/geoip-update.log"
log_level: "INFO"
quiet_mode: false
verbose: false

# Security
verify_ssl: true
user_agent: "GeoIP-Updater/1.0"

# File handling
create_dirs: true
preserve_timestamps: true
atomic_updates: true

Use configuration file:

./geoip-update.py --config config.yaml

⁠💻 Command Line Options

⁠Basic Options
# Required
-k, --api-key KEY          API authentication key
-e, --endpoint URL         API endpoint URL
-d, --directory DIR        Target directory for databases

# Database Selection
-b, --databases LIST       Specific databases (comma-separated) or "all"

# Configuration
-c, --config FILE          YAML configuration file path
⁠Advanced Options
# Performance
--concurrent NUM           Max concurrent downloads (default: 2)
--timeout SECONDS          Overall download ceiling per file (default: 1800; aborts early only on stall)
--chunk-size BYTES         Download chunk size (default: 8192)

# Retry Logic
--max-retries NUM          Maximum retry attempts (default: 3)
--retry-delay SECONDS      Initial retry delay (default: 2.0)
--retry-multiplier FLOAT   Retry delay multiplier (default: 2.0)

# Logging & Output
-l, --log-file FILE        Log file path
-q, --quiet               Suppress progress output
-v, --verbose             Detailed output and debugging
--log-level LEVEL         Log level (DEBUG, INFO, WARNING, ERROR)

# Behavior
--no-lock                 Skip lock file (allows concurrent runs)
--test-connection         Test API connectivity and exit
--dry-run                 Show what would be downloaded without action
--force-update            Download files even if up-to-date

⁠📋 Database Selection

⁠Selection Methods
# All databases
./geoip-update.py --databases all

# Specific databases by filename
./geoip-update.py --databases "GeoIP2-City.mmdb,GeoIP2-Country.mmdb"

# Using aliases (case-insensitive)
./geoip-update.py --databases "city,country,isp"

# Provider-specific
./geoip-update.py --databases "maxmind/*"
./geoip-update.py --databases "ip2location/*"
⁠Smart Database Discovery

The tool supports intelligent database name resolution:

# These all resolve to the same database
--databases "city"
--databases "City"  
--databases "GeoIP2-City"
--databases "GeoIP2-City.mmdb"

# Partial matching
--databases "proxy"  # Matches IP2PROXY-IP-PROXYTYPE-COUNTRY.BIN

# Multiple aliases
--databases "city,isp,proxy"
⁠Available Aliases
AliasFull Database NameProvider
cityGeoIP2-City.mmdbMaxMind
countryGeoIP2-Country.mmdbMaxMind
ispGeoIP2-ISP.mmdbMaxMind
connectionGeoIP2-Connection-Type.mmdbMaxMind
ipv4IP-COUNTRY-REGION-CITY-LATITUDE-LONGITUDE-ISP-DOMAIN-MOBILE-USAGETYPE.BINIP2Location
ipv6IPV6-COUNTRY-REGION-CITY-LATITUDE-LONGITUDE-ISP-DOMAIN-MOBILE-USAGETYPE.BINIP2Location
proxy (or ip2proxy)IP2PROXY-IP-PROXYTYPE-COUNTRY.BINIP2Location

⁠🚀 Performance Optimization

⁠Concurrent Downloads
# Conservative (good for limited bandwidth)
./geoip-update.py --concurrent 2

# Balanced (default)
./geoip-update.py --concurrent 4

# Aggressive (fast networks only)
./geoip-update.py --concurrent 8
⁠Timeout Configuration
# Quick timeout for local networks
./geoip-update.py --timeout 60

# Extended timeout for slow connections
./geoip-update.py --timeout 600

# Configuration file approach
timeout: 300
chunk_size: 16384  # Larger chunks for faster networks
⁠Progress Monitoring
# Standard progress bars
./geoip-update.py

# Quiet mode for automation
./geoip-update.py --quiet

# Verbose debugging
./geoip-update.py --verbose

⁠🔄 Automation & Scheduling

⁠Cron Example
# Daily updates at 3 AM
0 3 * * * /usr/local/bin/geoip-update.py --config /etc/geoip/config.yaml --quiet

# Weekly with logging
0 2 * * 0 /usr/local/bin/geoip-update.py --quiet --log-file /var/log/geoip-update.log
⁠systemd Service
[Unit]
Description=GeoIP Database Update
After=network-online.target

[Service]
Type=oneshot
ExecStart=/usr/local/bin/geoip-update.py --config /etc/geoip/config.yaml
User=geoip
StandardOutput=journal
StandardError=journal

[Install]
WantedBy=multi-user.target
⁠Docker Compose for Automation
version: '3.8'
services:
  geoip-updater:
    image: ytzcom/geoip-updater:latest
    environment:
      GEOIP_API_KEY: ${GEOIP_API_KEY}
      GEOIP_DATABASES: "city,country,isp"
    volumes:
      - geoip-data:/data
      - ./config.yaml:/config.yaml:ro
    command: ["python", "geoip-update.py", "--config", "/config.yaml"]
    
volumes:
  geoip-data:

⁠🛡️ Security Features

⁠Input Validation
  • API key format validation
  • Path traversal protection
  • File extension validation
  • Size limit enforcement
⁠Safe File Handling
  • Atomic file updates (temp → final)
  • Checksum verification (when available)
  • Permission preservation
  • Backup creation option
⁠SSL/TLS Security
# Configuration options
verify_ssl: true          # Verify SSL certificates
user_agent: "Custom/1.0"  # Custom user agent

⁠🏠️ Technical Details

⁠Architecture
  • Async I/O: aiohttp for concurrent downloads
  • Progress Tracking: tqdm for user feedback
  • Configuration: PyYAML for complex setups
  • Error Handling: Comprehensive exception management
⁠Dependencies
# Core requirements
aiohttp>=3.8.0      # Async HTTP client
pyyaml>=6.0         # YAML configuration
tqdm>=4.64.0        # Progress bars

# Optional enhancements
aiofiles>=0.8.0     # Async file I/O
ujson>=5.0.0        # Faster JSON parsing
⁠Error Handling
  • Network errors: Automatic retry with exponential backoff
  • API errors: Detailed error messages with troubleshooting tips
  • File errors: Fallback strategies and recovery options
  • Configuration errors: Clear validation messages

⁠🔍 Troubleshooting

⁠Common Issues

ModuleNotFoundError

# Install missing dependencies
pip install aiohttp pyyaml tqdm

# Or install all requirements
pip install -r requirements.txt

Permission Denied

# Fix directory permissions
sudo chown -R $USER:$USER /var/lib/geoip
chmod 755 /var/lib/geoip

# Or use user directory
./geoip-update.py --directory ~/geoip

API Connection Issues

# Test connectivity
./geoip-update.py --test-connection

# Debug with verbose output
./geoip-update.py --verbose

# Check SSL issues
./geoip-update.py --verbose --log-level DEBUG

Concurrent Download Issues

# Reduce concurrency
./geoip-update.py --concurrent 1

# Increase timeout
./geoip-update.py --timeout 600

# Check system limits
ulimit -n  # File descriptor limit
⁠Debug Mode

Enable comprehensive debugging:

# Maximum debugging
./geoip-update.py --verbose --log-level DEBUG

# Log to file for analysis
./geoip-update.py --verbose --log-file debug.log --log-level DEBUG

# Test mode (no actual downloads)
./geoip-update.py --dry-run --verbose

⁠🤝 Contributing

To modify this Python implementation:

  1. Setup environment:

    python -m venv venv
    source venv/bin/activate
    pip install -r requirements.txt
    
  2. Test changes:

    python geoip-update.py --test-connection
    python geoip-update.py --dry-run --verbose
    
  3. Submit pull request: Include tests and documentation updates

Tag summary

Content type

Image

Digest

sha256:af3bd9c12…

Size

51 MB

Last updated

2 days ago

docker pull ytzcom/geoip-updater