Giter Site home page Giter Site logo

external-ip's Introduction

external-ip

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.

Runtime

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)

Extend

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.

Example

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()
      .add_sources(sources)
      .build();
  let result = consensus.get_consensus();
  let value : Option<IpAddr>  = block_on(result);

Policies

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

Changelog

v1

  • Initial release

v2

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

v3

  • The default policy is now random

v4

  • Consensus is now not consumed when used

external-ip's People

Contributors

dependabot-preview[bot] avatar mellon85 avatar vladvasiliu avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.