Crate public_ip

Source
Expand description

Crate for resolving a devices’ own public IP address.

#[tokio::main]
async fn main() {
    // Attempt to get an IP address and print it.
    if let Some(ip) = public_ip::addr().await {
        println!("public ip address: {:?}", ip);
    } else {
        println!("couldn't get an IP address");
    }
}

Modules§

dnsdns-resolver
DNS resolver support.
httphttp-resolver
HTTP resolver support.

Enums§

Error
An error produced while attempting to resolve.
Version
The version of IP address to resolve.

Constants§

ALLdns-resolver or http-resolver
All builtin resolvers.

Traits§

Resolver
Trait implemented by IP address resolver.

Functions§

addrdns-resolver or http-resolver
Attempts to produce an IP address with all builtin resolvers (best effort).
addr_v4dns-resolver or http-resolver
Attempts to produce an IPv4 address with all builtin resolvers (best effort).
addr_v6dns-resolver or http-resolver
Attempts to produce an IPv6 address with all builtin resolvers (best effort).
addr_with
Given a Resolver and requested Version, attempts to produce an IP address (best effort).
addr_with_details
Given a Resolver and requested Version, attempts to produce an IP address along with the details of how it was resolved (best effort).
resolve
Given a Resolver and requested Version, produces a stream of Resolutions.

Type Aliases§

Details
The details of a resolution.
Resolutions
A Stream of Result<(IpAddr, Details), Error>.