Crates.io | ip2geo |
lib.rs | ip2geo |
version | 0.1.0 |
source | src |
created_at | 2023-03-20 23:16:35.834343 |
updated_at | 2023-03-20 23:16:35.834343 |
description | A small Rust library for getting the country code of IP addresses. |
homepage | https://github.com/hhhhhhhhhn/ip2geo |
repository | https://github.com/hhhhhhhhhn/ip2geo |
max_upload_size | |
id | 815676 |
size | 9,511,243 |
A small Rust library for getting the country code of IP addresses.
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);
}
The library takes a few seconds to parse the embedded binary data. After that, each search takes almost no time.
First, download the databases:
cd ipdb
sh download.sh
Then, turn them into a compressed binary for embedding:
cd download
cargo run