Ryan
Ryan

Reputation: 2404

How to get a list of the machine's IP addresses from Rust?

Specifically, I am interested in a programmatic way for acquiring a list of IP addresses such as those returned by ifconfig.

Preferably, the solution would be cross-platform.

Upvotes: 18

Views: 10936

Answers (1)

Evin Robertson
Evin Robertson

Reputation: 288

Check out the pnet crate:

extern crate pnet;

use pnet::datalink;

fn main() {
    for iface in datalink::interfaces() {
        println!("{:?}", iface.ips);
    }
}

Upvotes: 20

Related Questions