#ip-address #ip #asn #networking

asn-db

Lookup an IP address for matching ASN information in the database from https://iptoasn.com/

5 releases

0.1.4 May 1, 2020
0.1.3 Apr 30, 2020
0.1.2 Aug 27, 2019
0.1.1 Apr 25, 2019
0.1.0 Feb 20, 2019

#815 in Database interfaces

Download history 77/week @ 2024-06-17 84/week @ 2024-06-24 37/week @ 2024-07-01 55/week @ 2024-07-08 19/week @ 2024-07-15 35/week @ 2024-07-22 21/week @ 2024-07-29 13/week @ 2024-08-05 41/week @ 2024-08-12 9/week @ 2024-08-19 12/week @ 2024-08-26 2/week @ 2024-09-02 16/week @ 2024-09-09 17/week @ 2024-09-16 65/week @ 2024-09-23 23/week @ 2024-09-30

122 downloads per month
Used in asn-tools

MIT license

17KB
291 lines

Latest Version Documentation License

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:

  • 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.).

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.

Example

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

Dependencies

~1.8–2.6MB
~41K SLoC