1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
//! # 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
//! - **Async-first**: Built on tokio for high performance
//!
//! ## Quick Start
//!
//! ```rust,no_run
//! use ip_discovery::{get_ip, get_ipv4, get_ipv6};
//!
//! #[tokio::main]
//! async fn main() {
//! // Get any IP address (IPv4 or IPv6)
//! if let Ok(result) = get_ip().await {
//! println!("Public IP: {} (via {})", result.ip, result.provider);
//! }
//!
//! // Get IPv4 specifically
//! if let Ok(result) = get_ipv4().await {
//! println!("IPv4: {}", result.ip);
//! }
//! }
//! ```
//!
//! ## Custom Configuration
//!
//! ```rust,no_run
//! use ip_discovery::{Config, Strategy, Protocol, BuiltinProvider, get_ip_with};
//! use std::time::Duration;
//!
//! #[tokio::main]
//! async fn main() {
//! // Use only DNS providers with race strategy
//! let config = Config::builder()
//! .protocols(&[Protocol::Dns])
//! .strategy(Strategy::Race)
//! .timeout(Duration::from_secs(5))
//! .build();
//!
//! if let Ok(result) = get_ip_with(config).await {
//! println!("IP: {} (latency: {:?})", result.ip, result.latency);
//! }
//!
//! // Or pick specific providers
//! let config = Config::builder()
//! .providers(&[
//! BuiltinProvider::CloudflareDns,
//! BuiltinProvider::GoogleStun,
//! ])
//! .build();
//!
//! if let Ok(result) = get_ip_with(config).await {
//! println!("IP: {}", result.ip);
//! }
//! }
//! ```
pub use ;
pub use ;
pub use Provider;
pub use Resolver;
pub use ;
/// Get public IP address using default configuration.
///
/// Uses all available protocols with the [`Strategy::First`] fallback strategy
/// and a 10-second per-provider timeout.
///
/// # Errors
///
/// Returns [`Error::AllProvidersFailed`] if every provider fails.
pub async
/// Get public IPv4 address using default configuration.
///
/// # Errors
///
/// Returns [`Error::AllProvidersFailed`] if no provider returns an IPv4 address.
pub async
/// Get public IPv6 address using default configuration.
///
/// # Errors
///
/// Returns [`Error::NoProvidersForVersion`] if no provider supports IPv6.
pub async
/// Get public IP address with a custom [`Config`].
///
/// # Errors
///
/// Returns an [`Error`] variant depending on the strategy and provider results.
pub async
/// Get the primary local private IPv4 address.
///
/// This function queries the OS routing table by creating a connectionless
/// UDP socket and connecting it to a public destination. No network packets are sent.
/// Get the primary local private IPv6 address.
///
/// This function queries the OS routing table by creating a connectionless
/// UDP socket and connecting it to a public destination. No network packets are sent.