This Rust library can be used to look up IP address for matching ASN record that contains:
- network base IP address and mask (e.g.
ipnet::Ipv4Net
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.").
This crate requires data file ip2asn-v4.tsv
from IPtoASN and only supports IP v4 addresses (PR for v6 is welcome).
Example
Load database from ip2asn-v4.tsv
file and look up 1.1.1.1
IP address.
use Db;
use File;
use BufReader;
let db = form_tsv.unwrap;
let record = db.lookup.unwrap;
println!;
println!;
This prints:
Record {
ip: 16843008,
prefix_len: 24,
as_number: 13335,
country: "US",
owner: "CLOUDFLARENET - Cloudflare, Inc."
}
1.1.1.0/24
Note that this library also provides methods of storing the database in binary format for quicker load times.
See documentation for details at docs.rs.