Git Product home page Git Product logo

rust-public-ip's Introduction

Build Status Crate Docs

rust-public-ip

Find the public IP address of a device
Documentation hosted on docs.rs.

public-ip = "0.2"

Example usage

#[tokio::main]
async fn main() {
    // Attempt to get an IP address and print it.
    if let Some(ip) = public_ip::addr().await {
        println!("public ip address: {:?}", ip);
    } else {
        println!("couldn't get an IP address");
    }
}

rust-public-ip's People

Contributors

avitex avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

rust-public-ip's Issues

Picking IPv4 & IPv6 addresses

It would be great if this crate allowed picking the IP protocol version to resolve: IPv4/IPv6/Any.
On the dual-stack system, the hyper's happy eyeball protocol kicks in, and the resulting addresses are unpredictable.

Choose resolvers at random instead of always taking the first resolver

Most people will be using public_ip::addr (or one of the address family specific subvariants), which will always take the first enabled resolver, falling back to other enabled resolvers until it finds one that can complete the request.

To me, it would make more sense to shuffle the list of providers, so that the load is balanced among the different providers here.

I'd be willing to implement this, but I'd like to wait for feedback here if this is wanted and whether you have any strong opinions on how this should be implemented.

How to get an error message ein case of failure?

I use the resolver the basic way.
The resolver works in principal.
However the resolver fails to return an IP-address (i.e. returns None) on a different environment.

Is there a way to view what went wrong?

Environment 1: Windows 10 Pro
Environment 2: WSL2 (Ubuntu 18.04

an unknown tool name found in scoped lint: `rustdoc::all`

when attempting to include public_ip = "0.2" in Cargo.toml

error[E0710]: an unknown tool name found in scoped lint: `rustdoc::all`
  --> <Home>/.cargo/registry/src/github.com-1ecc6299db9ec823/public-ip-0.2.1/src/lib.rs:24:5
   |
24 |     rustdoc::all,
   |     ^^^^^^^

error: aborting due to previous error

For more information about this error, try `rustc --explain E0710`.
error: could not compile `public-ip`

ref: https://doc.rust-lang.org/rustdoc/lints.html

Filter resolvers to compatible address type instead of trying resolvers until a compatible address type comes out

Right now, when querying for a specific address family, this generates a stream of results that query any resolvers, and will potentially query an incompatible resolver, just to throw away the result because the result is incompatible. This potentially delays the result and causes unnecessary load on the backend providers side.

I'd be willing to implement this, but I'd like to wait for feedback here if this is wanted and whether you have any strong opinions on how this should be implemented.

ident.me as backend

They support querying v4 and v6 via HTTP(S), DNS, SSH, telnet(s), and STUN.

They also have a second service operated in a different datacenter, with tnedi.me.

Details on how they provide their service is available under https://api.ident.me/

Panic due to missing Tokio reactor

I'm trying to use this library in a project using the bevy game engine. Upon running I see this error:

thread 'main' panicked at 'there is no reactor running, must be called from the context of a Tokio 1.x runtime', /home/matthew/.cargo/registry/src/github.com-1ecc6299db9ec823/hyper-system-resolver-0.5.0/src/system.rs:43:9

The line I'm trying to run is:

 let public_ip = block_on(public_ip::addr()).unwrap();

This happens on all combinations of features I have tried.

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.