1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
//   Copyright 2019 IPinfo library developers
//
//   Licensed under the Apache License, Version 2.0 (the "License");
//   you may not use this file except in compliance with the License.
//   You may obtain a copy of the License at
//
//       http://www.apache.org/licenses/LICENSE-2.0
//
//   Unless required by applicable law or agreed to in writing, software
//   distributed under the License is distributed on an "AS IS" BASIS,
//   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
//   See the License for the specific language governing permissions and
//   limitations under the License.

//! # IPinfo: The rust library to lookup IP address information
//!
//! This is the Rust client library for the [IPinfo.io](https://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
//!
//! ```no_run
//! 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()),
//!   }
//! }
//! ```

/// Get crate version from cargo at build time.
const VERSION: &str = env!("CARGO_PKG_VERSION");

#[macro_use]
mod error;
mod api;
mod ipinfo;
mod util;
mod data;

pub use crate::ipinfo::*;
pub use api::*;
pub use error::*;
pub use util::*;
pub use data::*;