如何从Rust获取机器的IP地址列表? [英] How to get a list of the machine's IP addresses from Rust?

查看:788
本文介绍了如何从Rust获取机器的IP地址列表?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

特别是,我对以编程方式获取IP地址列表感兴趣,例如ifconfig返回的IP地址.

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.

推荐答案

查看 pnet板条箱:

extern crate pnet;

use pnet::datalink;

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

这篇关于如何从Rust获取机器的IP地址列表?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆