Skip to main content

Client

Struct Client 

Source
pub struct Client { /* private fields */ }
Expand description

Client for the ipdata.info IP geolocation, ASN, and threat-intelligence API.

Build one with Client::new (free tier) or Client::builder (to set an API key, custom base URL, or timeout).

Implementations§

Source§

impl Client

Source

pub fn new() -> Self

Creates a client targeting the free tier with the default 10s timeout.

Examples found in repository?
examples/quickstart.rs (line 9)
6fn main() {
7    // Free tier — no API key needed. For higher limits + batch, get a free
8    // key at https://ipdata.info/register and use Client::builder().api_key("...").
9    let client = Client::new();
10
11    let info = client.lookup("8.8.8.8").expect("lookup failed");
12    println!(
13        "{} is in {:?}, {:?} (ASN {:?} — {:?})",
14        info.ip, info.city, info.country, info.asn, info.asn_org
15    );
16
17    let threat = client
18        .threat_domain("example.com")
19        .expect("threat lookup failed");
20    println!("example.com listed as a threat: {}", threat.listed);
21}
Source

pub fn builder() -> ClientBuilder

Returns a ClientBuilder for configuring an API key, base URL, or timeout.

Source

pub fn base_url(&self) -> &str

Returns the base URL this client sends requests to.

Source

pub fn lookup(&self, ip: &str) -> Result<IpInfo, Error>

Returns the full geolocation record for ip. Pass "" for the caller’s own IP.

Examples found in repository?
examples/quickstart.rs (line 11)
6fn main() {
7    // Free tier — no API key needed. For higher limits + batch, get a free
8    // key at https://ipdata.info/register and use Client::builder().api_key("...").
9    let client = Client::new();
10
11    let info = client.lookup("8.8.8.8").expect("lookup failed");
12    println!(
13        "{} is in {:?}, {:?} (ASN {:?} — {:?})",
14        info.ip, info.city, info.country, info.asn, info.asn_org
15    );
16
17    let threat = client
18        .threat_domain("example.com")
19        .expect("threat lookup failed");
20    println!("example.com listed as a threat: {}", threat.listed);
21}
Source

pub fn geo(&self, ip: &str) -> Result<GeoInfo, Error>

Returns the compact geo subset for ip.

Source

pub fn asn(&self, ip: &str) -> Result<AsnBrief, Error>

Returns the compact ASN subset for ip.

Source

pub fn batch(&self, ips: &[&str]) -> Result<Vec<IpInfo>, Error>

Looks up many IPs in a single request. Requires an API key (paid tier); anonymous requests receive 403.

Source

pub fn asn_detail(&self, number: u32) -> Result<Value, Error>

Returns the detailed ASN record (prefixes, peering) as a raw JSON value; the shape is large and only loosely specified.

Source

pub fn asn_whois_history(&self, number: u32) -> Result<Value, Error>

Returns the ASN whois history as a raw JSON value.

Source

pub fn asn_changes(&self) -> Result<Value, Error>

Returns the ASN change feed as a raw JSON value.

Source

pub fn threat_domain(&self, domain: &str) -> Result<ThreatMatch, Error>

Looks up a domain in the threat-intel store.

Examples found in repository?
examples/quickstart.rs (line 18)
6fn main() {
7    // Free tier — no API key needed. For higher limits + batch, get a free
8    // key at https://ipdata.info/register and use Client::builder().api_key("...").
9    let client = Client::new();
10
11    let info = client.lookup("8.8.8.8").expect("lookup failed");
12    println!(
13        "{} is in {:?}, {:?} (ASN {:?} — {:?})",
14        info.ip, info.city, info.country, info.asn, info.asn_org
15    );
16
17    let threat = client
18        .threat_domain("example.com")
19        .expect("threat lookup failed");
20    println!("example.com listed as a threat: {}", threat.listed);
21}
Source

pub fn threat_hash(&self, hash: &str) -> Result<ThreatMatch, Error>

Looks up a file hash (md5/sha1/sha256) in the threat-intel store.

Source

pub fn threat_url(&self, url: &str) -> Result<ThreatMatch, Error>

Looks up a URL in the threat-intel store (the server falls back to the URL’s domain on a miss).

Trait Implementations§

Source§

impl Default for Client

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.