#geolocation #ip-address #ip

ip2geo

A small Rust library for getting the country code of IP addresses

1 unstable release

0.1.0 Mar 20, 2023

#38 in #geolocation

Download history 13/week @ 2024-09-23 45/week @ 2024-10-07 24/week @ 2024-10-14 45/week @ 2024-10-21 22/week @ 2024-10-28 31/week @ 2024-11-04

123 downloads per month

Custom license

1.5MB

ip2geo

A small Rust library for getting the country code of IP addresses.

Usage

use ip2geo;
use std::net::IpAddr;

fn main() {
    let address: IpAddr = "152.179.124.137".parse().unwrap();
    let country_code = ip2geo::search(address).unwrap().country;
    println!("{}", country_code);
}

Note on performance

The library takes a few seconds to parse the embedded binary data. After that, each search takes almost no time.

Compilation instructions

First, download the databases:

cd ipdb
sh download.sh

Then, turn them into a compressed binary for embedding:

cd download
cargo run

Dependencies

~2–9.5MB
~77K SLoC