iptocc
Fast, offline IPv4/IPv6 to ISO 3166-1 alpha-2 country code lookup.
Python and WASM bindings built on this crate live in the same repository.
[!NOTE] Country codes reflect the country assigned by a Regional Internet Registry (RIR) to each IP block, not where the block is being used. RIR data agrees with MaxMind for ~95% of IPv4 addresses and has minimal discrepancies for IPv6 (Zander, 2012).
Features
- Offline lookup, no API keys, no network calls
- IPv4 and IPv6 in one call
- Generic
country_code<T: IpAddress>(input)accepts&str,String,Ipv4Addr,Ipv6Addr, orIpAddr - Batch
country_codestakes any iterable of the above - Lookup data embedded via
include_bytes!; no runtime file I/O - Nanosecond-scale lookups: ~1.3 ns typed, ~6 ns string. See BENCHMARK.md.
iptoccCLI installed withcargo install iptocc- Data refreshed nightly from the five Regional Internet Registries (RIRs)
Install
Usage
use ;
assert_eq!;
assert_eq!;
assert_eq!;
let codes = country_codes;
assert_eq!;
Typed inputs are also accepted and skip the string parsing step:
use Ipv4Addr;
use country_code;
assert_eq!;
A CLI is installed by cargo install iptocc: