Expand description
§ip-discovery
A lightweight, high-performance Rust library for detecting public IP addresses via DNS, HTTP, and STUN protocols with fallback support.
§Features
- Multi-protocol support: DNS, HTTP/HTTPS, STUN (RFC 5389)
- Trusted providers: Google, Cloudflare, AWS, OpenDNS
- Fallback mechanism: Automatic retry with different providers
- Flexible strategies: First success, race (fastest), or consensus
- Zero-dependency protocols: DNS and STUN use raw UDP sockets
- Synchronous & Asynchronous: Zero-dependency blocking API by default, or Tokio async via feature
§Synchronous (Blocking) Quick Start
use ip_discovery::blocking::{get_ip, get_ipv4};
// Get any IP address (IPv4 or IPv6) synchronously without Tokio runtime
if let Ok(result) = get_ip() {
println!("Public IP: {} (via {})", result.ip, result.provider);
}
// Get IPv4 specifically
if let Ok(result) = get_ipv4() {
println!("IPv4: {}", result.ip);
}§Asynchronous Quick Start (with tokio feature)
use ip_discovery::{get_ip, get_ipv4};
// Get any IP address asynchronously
if let Ok(result) = get_ip().await {
println!("Public IP: {} (via {})", result.ip, result.provider);
}Modules§
- blocking
- Synchronous, blocking IP detection engine.
- dns
- DNS protocol implementation for public IP detection
- http
- HTTP/HTTPS protocol implementation for public IP detection
- stun
- STUN protocol implementation for public IP detection
Structs§
- Config
- Configuration for IP detection
- Config
Builder - Builder for
Config. - Provider
Error - Error from a specific provider
- Provider
Result - Result from a successful IP lookup
- Resolver
- Coordinates IP detection across configured providers.
Enums§
- Builtin
Provider - Built-in IP detection providers
- Error
- Main error type for IP detection
- IpVersion
- IP version preference
- Protocol
- Protocol used to detect public IP
- Strategy
- Strategy for resolving the public IP across multiple providers.
Traits§
- Blocking
Provider - Trait for synchronous IP detection providers
- Provider
- Trait for asynchronous IP detection providers
Functions§
- get_ip
- Get public IP address using default configuration asynchronously.
- get_
ip_ with - Get public IP address with a custom
Configasynchronously. - get_
ipv4 - Get public IPv4 address using default configuration asynchronously.
- get_
ipv6 - Get public IPv6 address using default configuration asynchronously.
- get_
private_ ip - Get the primary local private IPv4 address.
- get_
private_ ipv6 - Get the primary local private IPv6 address.
Type Aliases§
- Boxed
Blocking Provider - Type-erased synchronous provider, used internally to store heterogeneous providers.
- Boxed
Provider - Type-erased asynchronous provider, used internally to store heterogeneous providers.