Git Product home page Git Product logo

local-ip-address's Introduction

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)

local-ip-address's People

Contributors

estebanborai avatar dependabot[bot] avatar nicguzzo avatar cgzones avatar hummingly avatar alexkrob avatar kristian1108 avatar nashley avatar d1plo1d avatar tudyx avatar

Watchers

James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.