#ip-geolocation #proxy

ip2location

Find geo information & proxy information based on the given IP using IP2Location BIN databases

22 releases

Uses new Rust 2024

new 0.6.1 Feb 12, 2026
0.6.0 Sep 5, 2025
0.5.4 Dec 16, 2024
0.5.3 Sep 9, 2024
0.1.1 Jan 7, 2021

#171 in Database interfaces

Download history 494/week @ 2025-10-28 574/week @ 2025-11-04 360/week @ 2025-11-11 461/week @ 2025-11-18 365/week @ 2025-11-25 455/week @ 2025-12-02 450/week @ 2025-12-09 362/week @ 2025-12-16 205/week @ 2025-12-23 91/week @ 2025-12-30 255/week @ 2026-01-06 101/week @ 2026-01-13 302/week @ 2026-01-20 377/week @ 2026-01-27 239/week @ 2026-02-03 420/week @ 2026-02-10

1,358 downloads per month
Used in 2 crates

Custom license

69KB
1.5K SLoC

IP2Location & IP2Proxy

Crates.io Documentation

Linux Arm7 Linux x86_64 macOS x86_64 Windows x86_64

This library reads the IP2Location DB format for both IP2Location and IP2Proxy and returns geo information for the given IP.

Features

  • Zero-copy — string fields borrow directly from the memory-mapped file
  • Memory-mapped I/O — database is mmap’d at open time, no heap allocation on the lookup path
  • Supports both IP2Location (geolocation) and IP2Proxy (proxy detection) BIN databases
  • Handles IPv4, IPv6, 6to4, Teredo, and IPv4-mapped IPv6 addresses

Requirements

  • Rust 1.85+ (edition 2024)

Building

  • debug
cargo b
  • release
cargo b --release

Testing

cargo t -v

Usage

[dependencies]
ip2location = "0.6"

Example

use ip2location::{error, Record, DB};

const IPV4BIN: &str = "data/IP2LOCATION-LITE-DB1.BIN";
const IPV6BIN: &str = "data/IP2LOCATION-LITE-DB1.IPV6.BIN";
const IP2PROXYBIN: &str = "data/IP2PROXY-IP-COUNTRY.BIN";

// Lookup an IPv4 in the IP2Location IPv6 BIN Database
fn ip_lookup_in_ipv6bin() -> Result<(), error::Error> {
    let db = DB::from_file(IPV6BIN)?;
    let record = db.ip_lookup("43.224.159.155".parse().unwrap())?;
    if let Record::LocationDb(rec) = record {
        assert!(rec.country.is_some());
        assert_eq!(rec.country.as_ref().unwrap().short_name, "IN");
        assert_eq!(rec.country.as_ref().unwrap().long_name, "India");
    }
    Ok(())
}

// Lookup an IPv4 in the IP2Location IPv4 BIN Database
fn ip_lookup_in_ipv4bin() -> Result<(), error::Error> {
    let db = DB::from_file(IPV4BIN)?;
    let record = db.ip_lookup("43.224.159.155".parse().unwrap())?;
    if let Record::LocationDb(rec) = record {
        assert!(rec.country.is_some());
        assert_eq!(rec.country.as_ref().unwrap().short_name, "IN");
        assert_eq!(rec.country.as_ref().unwrap().long_name, "India");
    }
    Ok(())
}

// Lookup an IP in the Proxy Database
fn ip_lookup_in_proxy_bin() -> Result<(), error::Error> {
    let db = DB::from_file(IP2PROXYBIN)?;
    let record = db.ip_lookup("1.1.1.1".parse().unwrap())?;
    if let Record::ProxyDb(rec) = record {
        assert!(rec.country.is_some());
    }
    Ok(())
}

Executing the Example

cargo build --examples

# IP2Location Example
./target/debug/examples/lookup data/IP2LOCATION-LITE-DB1.IPV6.BIN 2a01:cb08:8d14::

# IP2Proxy Example
./target/debug/examples/lookup data/IP2PROXY-IP-COUNTRY.BIN 1.1.1.1

License

This is free software, licensed under the MIT license.

Ip2Location Databases:


Sriram

Dependencies

~1.3–2.3MB
~48K SLoC