[−][src]Crate public_ip
Crate providing a generic way to find the public IP address of the device it runs on, along with with some built in resolvers
Basic Usage
use async_std::task; use public_ip::{dns, http, ToResolver, BoxToResolver}; // List of resolvers to try and get an IP address from let resolver = vec![ BoxToResolver::new(dns::OPENDNS_RESOLVER), BoxToResolver::new(http::HTTP_IPIFY_ORG_RESOLVER), ].to_resolver(); // Attempt to get an IP address and print it if let Some(ip) = task::block_on(public_ip::resolve_address(resolver)) { println!("public ip address: {:?}", ip); } else { println!("couldn't get an IP address"); }
Usage with Resolution
use std::any::Any; use async_std::task; use public_ip::{dns, ToResolver, Resolution}; // List of resolvers to try and get an IP address from let resolver = dns::OPENDNS_RESOLVER.to_resolver(); // Attempt to get an IP address and print it if let Some(resolution) = task::block_on(public_ip::resolve(resolver)) { if let Some(resolution) = Any::downcast_ref::<dns::DnsResolution>(&resolution) { println!("public ip address {:?} resolved from {:?} ({:?})", resolution.address(), resolution.name(), resolution.server(), ); } } else { println!("couldn't get an IP address"); }
Modules
dns | |
http |
Structs
BoxResolver | Boxed |
BoxToResolver | Boxed |
DefaultResolverContext | Default resolver context (see |
ListResolver | A resolver for combining a list of resolvers into one |
ResultResolver | A resolver that wraps a result that is either a resolver, or an error produced while creating it |
Traits
AutoResolverContext | Trait when implemented provides a default context for all builtin resolvers |
Resolution | The successful product of a resolver |
ResolutionError | An error produced while attempting to resolve |
Resolver | Trait implemented by IP address resolvers |
ResolverContext | Base context used by resolvers for specifying resolver environment |
ToResolver | Trait implemented for types that can be converted into a resolver given a resolver context |
Functions
resolve | Attempts to resolve to a resolution (best effort) |
resolve_address | Attempts resolve a single address (best effort) |
resolve_stream | Resolves a stream with a default context |
Type Definitions
BoxResolution | Boxed |
BoxResolutionError | Boxed |
BoxResolutionStream | Boxed |