Skip to main content

Crate ip_discovery

Crate ip_discovery 

Source
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
ConfigBuilder
Builder for Config.
ProviderError
Error from a specific provider
ProviderResult
Result from a successful IP lookup
Resolver
Coordinates IP detection across configured providers.

Enums§

BuiltinProvider
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§

BlockingProvider
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 Config asynchronously.
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§

BoxedBlockingProvider
Type-erased synchronous provider, used internally to store heterogeneous providers.
BoxedProvider
Type-erased asynchronous provider, used internally to store heterogeneous providers.