#ip-address #ip #networking #local #socket-address #linux-macos #web

local-ip-address

Retrieve system's local IP address and Network Interfaces/Adapters on Linux, macOS and Windows

24 releases

0.6.3 Sep 17, 2024
0.6.1 Feb 25, 2024
0.5.6 Sep 27, 2023
0.5.4 Jul 27, 2023
0.4.2 Jul 14, 2021

#9 in Network programming

Download history 66612/week @ 2024-08-03 68880/week @ 2024-08-10 67087/week @ 2024-08-17 77246/week @ 2024-08-24 91386/week @ 2024-08-31 81245/week @ 2024-09-07 76861/week @ 2024-09-14 83438/week @ 2024-09-21 79597/week @ 2024-09-28 89784/week @ 2024-10-05 93597/week @ 2024-10-12 94910/week @ 2024-10-19 99892/week @ 2024-10-26 94533/week @ 2024-11-02 97915/week @ 2024-11-09 99877/week @ 2024-11-16

409,087 downloads per month
Used in 169 crates (115 directly)

MIT/Apache

55KB
1K SLoC

local-ip-address

Retrieve system's local IP address and Network Interfaces/Adapters on Linux, Windows, and macOS (and other BSD-based systems).

Crates.io Documentation Build Clippy Formatter

Usage

Get the local IP address of your system by executing the local_ip function:

use local_ip_address::local_ip;

fn main() {
    let my_local_ip = local_ip().unwrap();

    println!("This is my local IP address: {:?}", my_local_ip);
}

Retrieve all the available network interfaces from both, the AF_INET and the AF_INET6 family by executing the list_afinet_netifas function:

use local_ip_address::list_afinet_netifas;

fn main() {
    let network_interfaces = list_afinet_netifas().unwrap();

    for (name, ip) in network_interfaces.iter() {
        println!("{}:\t{:?}", name, ip);
    }
}

Underlying approach on retrieving network interfaces or the local IP address may differ based on the running operative system.

OS Approach
Linux Establishes a Netlink socket interchange to retrieve network interfaces
BSD-based Uses of getifaddrs to retrieve network interfaces
Windows Consumes Win32 API's to retrieve the network adapters table

Operating System Support

Current supported platforms include:

  • Linux (requires at least v0.1.0);
  • macOS (requires at least v0.1.0);
  • Windows (requires at least v0.3.0);
  • Other BSD-based (requires at least v0.5.0); including:
    • FreeBSD
    • OpenBSD
    • NetBSD
    • DragonFly

Please note that we only test the BSD implementation of this on macOS and FreeBSD, under the assumption that other BSD-based systems will behave similarly. If you have any complications using this library on the other BSD-based, please create an issue.

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)

Dependencies

~0.2–8.5MB
~78K SLoC