Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 809
Ryan Avatar asked May 18 '17 19:05

Ryan


People also ask

How can I see all IP addresses on a network terminal?

Open a terminal window to get to the command line. Enter the command arp -a to get a list of all IP addresses on your network.

How can I see all IP addresses on my network in cmd windows?

From the desktop, navigate through; Start > Run> type "cmd.exe". A command prompt window will appear. At the prompt, type "ipconfig /all". All IP information for all network adapters in use by Windows will be displayed.


1 Answers

Check out the pnet crate:

extern crate pnet;

use pnet::datalink;

fn main() {
    for iface in datalink::interfaces() {
        println!("{:?}", iface.ips);
    }
}
like image 70
Evin Robertson Avatar answered Sep 21 '22 20:09

Evin Robertson