liranringel / ipconfig

Get network adapters information for windows (written in Rust).
Apache License 2.0
37 stars 15 forks source link

[Question] How to know which interface is the one used? #36

Closed Geobert closed 4 years ago

Geobert commented 4 years ago

Hi,

thank you very much for this useful crate :D

I'm trying to get the local ip address of the computer and as I have VirtualBox installed, I have multiple interfaces.

How can I distinguish the real one from the virtual one? Both are EthernetCsmacd.

I'd like to create a server which as the IP address of my computer :)

LuoZijun commented 4 years ago

route -n get default ?

Geobert commented 4 years ago

Thank you, but I mean by using the crate's API

liranringel commented 4 years ago

You can check which adapter has gateways (>0). It's already exposed in master but not in version 0.2.1, so I'll release it now for you :) Does it help?

Geobert commented 4 years ago

Yeah it does thanks! Unfortunately, the project I was working on and needed that is cancelled ^^' But I will be handy to have anyway!

laduke commented 1 year ago

Windows uses the adapter with the lowest metric.

oops, sorry for posting in an old thread. there's already an example https://github.com/liranringel/ipconfig/blob/master/examples/priority_list.rs