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

后端 未结 1 675
旧时难觅i
旧时难觅i 2021-02-19 19:52

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

1条回答
  •  日久生厌
    2021-02-19 20:20

    Check out the pnet crate:

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

    0 讨论(0)
提交回复
热议问题