local-ip-address 0.2.0

Retrive system's local IP address
Documentation

Crates.io Documentation Build Clippy Formatter

A wrapper on getifaddrs which retrieves host's network interfaces. Handy functions are provided such as local_ip which retrieve the local IP address based on the host system

use std::net::IpAddr;
use local_ip_address::local_ip;

assert!(matches!(local_ip().unwrap(), IpAddr));

You are able to iterate over a vector of tuples where the first element of the tuple is the name of the network interface and the second is the IP address.

use std::net::IpAddr;
use local_ip_address::find_af_inet;

let ifas = find_af_inet().unwrap();

if let Some((_, ipaddr)) = ifas
.iter()
.find(|(name, ipaddr)| *name == "en0" && matches!(ipaddr, IpAddr::V4(_))) {
    println!("This is your local IP address: {:?}", ipaddr);
    // This is your local IP address: 192.168.1.111
    assert!(matches!(ipaddr, IpAddr));
}

Release

In order to create a release you must push a Git tag as follows

git tag -a <version> -m <message>

Example

git tag -a v0.1.0 -m "First release"

Tags must follow semver conventions Tags must be prefixed with a lowercase v letter.

Then push tags as follows:

git push origin main --follow-tags

Contributing

Every contribution to this project is welcome. Feel free to open a pull request, an issue or just by starting this project.

License

Distributed under the terms of both the MIT license and the Apache License (Version 2.0)