Crates.io | asn-db2 |
lib.rs | asn-db2 |
version | 0.2.2 |
source | src |
created_at | 2023-08-03 14:52:29.377986 |
updated_at | 2023-08-05 18:26:41.967457 |
description | Lookup an IP address for matching ASN information in the database from https://iptoasn.com/ |
homepage | |
repository | https://git.marie.cologne/marie/asn-db |
max_upload_size | |
id | 933694 |
size | 54,552 |
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:
1.1.1.0/24
),13335
),US
),CLOUDFLARENET - Cloudflare, Inc.
).Both IPv4 and IPv6 addresses and networks are supported.
Load database from ip2asn-v4.tsv
file and lookup 1.1.1.1
IP address.
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:
Entry {
subnet: 1.1.1.0/24,
as_number: 13335,
country: "US",
owner: "CLOUDFLARENET",
}