Crates.io | external-ip |
lib.rs | external-ip |
version | 5.2.0 |
source | src |
created_at | 2019-12-30 01:06:27.320917 |
updated_at | 2024-04-26 20:09:07.539303 |
description | Asynchronous library to retrieve the system external IP |
homepage | |
repository | https://github.com/mellon85/external-ip |
max_upload_size | |
id | 193399 |
size | 33,259 |
Finds the current external IP address contacting http and dns external services.
If at least one of the sources replies the reply with the highest occurrences will be reported as the IP address.
Three functions provides sets of known working sources.
get_http_sources
Returns all known http sourcesget_dns_sources
Returns all known dns sourcesget_sources
Returns all sources combinedAdditionally a single igd source can be instantiated if the feature is enabled
(discover_igd
), to retrieve the IP from an home router.
If the feature is enabled get_sources
will return it as a source too.
It requires to run with Tokio runtime due to the dependency on hyper if you use the HTTP resolver. The DNS resolver can work with other executors at the moment. (tested with futures)
It's possible to extend how the sources dynamically via the API as long as the Source interface is implemented and it's passed as a boxed trait object.
For ease of use a single async function is enough to obtain the IP trying with all the default sources enabled
let result = external_ip::get_ipv4();
let value : Option<IpAddr> = block_on(result);
let result = external_ip::get_ipv6();
let value : Option<IpAddr> = block_on(result);
The library supports 3 consensus policies. The default policy is Random
It's possible to select a specific address family to resolve to and all resolver will try to resolve to that or fail.