ip-tools 0.2.0

A CLI tool and library to retrieve the local IP address and list network interfaces
docs.rs failed to build ip-tools-0.2.0
Please check the build logs for more information.
See Builds for ideas on how to fix a failed build, or Metadata for how to configure docs.rs builds.
If you believe this is docs.rs' fault, open an issue.

ip-tools

Crates.io Docs.rs CI Coverage Status Rust GitHub Template

A small CLI tool to list network interfaces and retrieve the local IP address.

Installation

Cargo

  • Install the rust toolchain in order to have cargo installed by following this guide.
  • run cargo install ip-tools

Usage

Get the local IP address

ip-tools get

Example output:

192.168.1.100

List all network interfaces

ip-tools list

Example output:

lo: 127.0.0.1
eth0: 192.168.1.100
wlan0: 10.0.0.5

JSON output

Pass --json for machine-readable output (useful for scripting and automation):

ip-tools get --json
ip-tools list --json

Example output for get --json:

{"ip":"192.168.1.100"}

Example output for list --json:

[{"name":"lo","ip":"127.0.0.1"},{"name":"eth0","ip":"192.168.1.100"}]

Show help

ip-tools --help

Library usage

ip-tools is also published as a library crate (ip_tools). See the API documentation for details.

use ip_tools::{get_local_ip, list_net_ifs};

// Retrieve the local IP address
if let Ok(ip) = get_local_ip() {
    println!("local IP: {ip}");
}

// List all network interfaces
if let Ok(interfaces) = list_net_ifs() {
    for (name, ip) in &interfaces {
        println!("{name}: {ip}");
    }
}

A runnable example is provided in examples/ip_info.rs:

cargo run --example ip_info

License

Licensed under either of

at your option.

Contribution

Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.

See CONTRIBUTING.md.