Crates.io | asn-db |
lib.rs | asn-db |
version | 0.1.4 |
source | src |
created_at | 2019-02-20 09:46:46.186669 |
updated_at | 2020-05-01 09:39:42.748464 |
description | Lookup an IP address for matching ASN information in the database from https://iptoasn.com/ |
homepage | https://jpastuszek.net/asn/ |
repository | https://sr.ht/~jpastuszek/asn-db/ |
max_upload_size | |
id | 115929 |
size | 112,182 |
asn-db
is a Rust library that can load and index ASN database (ip2asn-v4.tsv
file) from IPtoASN website.
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.
).It is also possible to write and then read optimized binary representation of the database to a file for fast load times. Note that at this time only IPv4 records are supported.
Load database from ip2asn-v4.tsv
file and lookup 1.1.1.1
IP address.
use asn_db::Db;
use std::fs::File;
use std::io::BufReader;
let db = Db::form_tsv(BufReader::new(File::open("ip2asn-v4.tsv").unwrap())).unwrap();
let record = db.lookup("1.1.1.1".parse().unwrap()).unwrap();
println!("{:#?}", record);
println!("{:#?}", record.network());
This prints:
Record {
ip: 16843008,
prefix_len: 24,
as_number: 13335,
country: "US",
owner: "CLOUDFLARENET - Cloudflare, Inc."
}
1.1.1.0/24