GeoIP database updater with support for MaxMind and IP2Location
10K+
Full-featured Python client for GeoIP database updates with async downloads, configuration files, and advanced features.
# 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
# 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
| Variable | Default | Description |
|---|---|---|
GEOIP_API_KEY | (required) | Your authentication API key |
GEOIP_API_ENDPOINT | https://geoipdb.net/auth | API endpoint URL |
GEOIP_TARGET_DIR | /data | Database storage directory |
GEOIP_DATABASES | all | Databases to download |
GEOIP_CONFIG_FILE | - | Path to configuration file |
GEOIP_LOG_FILE | - | Log file path |
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
# 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
# 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
# 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/*"
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"
| Alias | Full Database Name | Provider |
|---|---|---|
city | GeoIP2-City.mmdb | MaxMind |
country | GeoIP2-Country.mmdb | MaxMind |
isp | GeoIP2-ISP.mmdb | MaxMind |
connection | GeoIP2-Connection-Type.mmdb | MaxMind |
ipv4 | IP-COUNTRY-REGION-CITY-LATITUDE-LONGITUDE-ISP-DOMAIN-MOBILE-USAGETYPE.BIN | IP2Location |
ipv6 | IPV6-COUNTRY-REGION-CITY-LATITUDE-LONGITUDE-ISP-DOMAIN-MOBILE-USAGETYPE.BIN | IP2Location |
proxy (or ip2proxy) | IP2PROXY-IP-PROXYTYPE-COUNTRY.BIN | IP2Location |
# 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
# 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
# Standard progress bars
./geoip-update.py
# Quiet mode for automation
./geoip-update.py --quiet
# Verbose debugging
./geoip-update.py --verbose
# 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
[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
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:
# Configuration options
verify_ssl: true # Verify SSL certificates
user_agent: "Custom/1.0" # Custom user agent
aiohttp for concurrent downloadstqdm for user feedbackPyYAML for complex setups# 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
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
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
To modify this Python implementation:
Setup environment:
python -m venv venv
source venv/bin/activate
pip install -r requirements.txt
Test changes:
python geoip-update.py --test-connection
python geoip-update.py --dry-run --verbose
Submit pull request: Include tests and documentation updates
Content type
Image
Digest
sha256:af3bd9c12…
Size
51 MB
Last updated
2 days ago
docker pull ytzcom/geoip-updater