Crate ipinfo

source ·
Expand description

IPinfo: The rust library to lookup IP address information

This is the Rust client library for the IPinfo.io IP address API. It allows you to lookup your own IP address, or get any of the following details for an IP:

  • IP geolocation (city, region, country, postal code, latitude and longitude)
  • ASN details (ISP or network operator, associated domain name, and type, such as business, hosting or company)
  • Company details (the name and domain of the business that uses the IP address)
  • Carrier details (the name of the mobile carrier and MNC and MCC for that carrier if the IP is used exclusively for mobile traffic)

Features

  • Smart LRU cache for cost and quota savings.
  • Structured and type checked query results.
  • Bulk IP address lookup using IPinfo batch API.

Example

use ipinfo::{IpInfo, IpInfoConfig};
#[tokio::main]
async fn main() {
  // Setup token and other configurations.
  let config = IpInfoConfig { token: Some("my token".to_string()), ..Default::default() };

  // Setup IpInfo structure and start looking up IP addresses.
  let mut ipinfo = IpInfo::new(config).expect("should construct");
  let res = ipinfo.lookup("8.8.8.8").await;

  match res {
    Ok(r) => println!("{}: {}", "8.8.8.8", r.hostname.as_ref().unwrap()),
    Err(e) => println!("error occurred: {}", &e.to_string()),
  }
}

Macros

  • Create a new error (of a given kind) with a formatted message

Structs

Enums

  • An enum of errors to represent the possible kinds of IpError.

Constants

Functions

  • returns a boolean indicating whether an IP address is bogon supports both IPv4 and IPv6