#dns #http #igd #ip #external


Asynchronous library to retrieve the system external IP

9 stable releases (4 major)

4.2.0 Jan 30, 2023
4.1.0 Jan 10, 2021
4.0.0 Oct 3, 2020
3.0.0 Jun 28, 2020
0.1.0 Dec 30, 2019

#16 in #ip

Download history 282/week @ 2023-02-01 456/week @ 2023-02-08 365/week @ 2023-02-15 455/week @ 2023-02-22 323/week @ 2023-03-01 438/week @ 2023-03-08 211/week @ 2023-03-15 140/week @ 2023-03-22 292/week @ 2023-03-29 365/week @ 2023-04-05 320/week @ 2023-04-12 387/week @ 2023-04-19 490/week @ 2023-04-26 139/week @ 2023-05-03 482/week @ 2023-05-10 902/week @ 2023-05-17

2,082 downloads per month
Used in 2 crates

MIT license

599 lines


Build Status

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 sources
  • get_dns_sources Returns all known dns sources
  • get_sources Returns all sources combined

Additionally 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_ip();
  let value : Option<IpAddr> = block_on(result);

This is the same as doing

  let sources: external_ip::Sources = external_ip::get_sources();
  let consensus = external_ip::ConsensusBuilder::new()
  let result = consensus.get_consensus();
  let value : Option<IpAddr>  = block_on(result);


The library supports 3 consensus policies. The default policy is Random

  • All Query all sources in parallel and return the most common response
  • First Query the sources one by one and return the first success
  • Random Query the sources one by one in random order and return the first success



  • Initial release


  • Based on trust dns instead of c-ares. Now requires less external dependencies (only ssl at the moment)


  • The default policy is now random


  • Consensus is now not consumed when used


~321K SLoC