[![Latest Version]][crates.io] [![Documentation]][docs.rs] ![License] `asn-db2` is a Rust library that can load and index [ASN] databases (`ip2asn-v4.tsv`, `ip2asn-v6.tsv`, `ip2asn-combined.tsv` files) from [IPtoASN] website. *This crate is a rewritten fork of Jakub Pastuszek's [asn-db] crate.* Once loaded it can be used to lookup an IP address for matching [ASN] record that contains: * network base IP address and mask (e.g. [ipnet::Ipv4Net](https://docs.rs/ipnet/2.3.0/ipnet/struct.Ipv4Net.html) value like `1.1.1.0/24`), * assigned AS number (e.g. `13335`), * owner country code (e.g. `US`), * owner information (e.g. `CLOUDFLARENET - Cloudflare, Inc.`). Both IPv4 and IPv6 addresses and networks are supported. # Example Load database from `ip2asn-v4.tsv` file and lookup `1.1.1.1` IP address. ```rust use asn_db2::Ipv4Database; use std::fs::File; use std::io::BufReader; let db = Ipv4Database::from_reader(BufReader::new(File::open("ip2asn-v4.tsv").unwrap())).unwrap(); let entry = db.lookup("1.1.1.1".parse().unwrap()).unwrap(); println!("{:#?}", entry); ``` This prints: ```noformat Entry { subnet: 1.1.1.0/24, as_number: 13335, country: "US", owner: "CLOUDFLARENET", } ``` [asn-db]: https://crates.io/crates/asn-db [ASN]: https://en.wikipedia.org/wiki/Autonomous_system_%28Internet%29#Assignment [IPtoASN]: https://iptoasn.com/ [crates.io]: https://crates.io/crates/asn-db2 [Latest Version]: https://img.shields.io/crates/v/asn-db2.svg [Documentation]: https://docs.rs/asn-db2/badge.svg [docs.rs]: https://docs.rs/asn-db2 [License]: https://img.shields.io/crates/l/asn-db2.svg