ip_address_list v0.1.1

Retrieve the IP addresses (both IPv4 and IPv6) associated with the network interfaces on a system

Crystal IP Address List Library

Crystal CI GitHub release License

This library provides functionality to retrieve the IP addresses (both IPv4 and IPv6) associated with the network interfaces on a system. It is a port of Ruby's ip_address_list method from the Socket class.

Features

  • Retrieve both IPv4 and IPv6 addresses from network interfaces.
  • Supports Windows, Linux, and macOS.
  • Easy-to-use interface, returning a list of Socket::IPAddress objects.

Installation

  1. Add the dependency to your shard.yml:

    dependencies:
      ip_address_list:
        github: mamantoha/ip_address_list
    
  2. Run shards install

Usage

require "ip_address_list"

p! Socket.ip_address_list
# => [Socket::IPAddress(127.0.0.1:0),
#     Socket::IPAddress(192.168.31.229:0),
#     Socket::IPAddress(172.17.0.1:0),
#     Socket::IPAddress([::1]:0),
#     Socket::IPAddress([fdcc:60fc:349d:2fcf:7e6:1635:e1a7:1fb6]:0),
#     Socket::IPAddress([fe80::c8e3:857d:43c8:cec3]:0)
#     ...]

Technical Notes

Windows Implementation

On Windows, this library uses the GetAdaptersAddresses function to retrieve network interface information, including IP addresses. You can find more information about GetAdaptersAddresses in the Microsoft documentation.

Linux and macOS Implementation

On Linux and macOS, the library uses the getifaddrs function to gather network interface information. This function is part of the standard C library and provides a linked list of structures describing the network interfaces of the local system. More details about getifaddrs can be found in the Linux man page and the macOS documentation.

Contributing

  1. Fork it (https://github.com/mamantoha/ip_address_list/fork)
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Commit your changes (git commit -am 'Add some feature')
  4. Push to the branch (git push origin my-new-feature)
  5. Create a new Pull Request

Contributors

Repository

ip_address_list

Owner
Statistic
  • 1
  • 0
  • 0
  • 2
  • 0
  • about 1 month ago
  • September 17, 2024
License

MIT License

Links
Synced at

Wed, 06 Nov 2024 22:57:31 GMT

Languages