Last active
October 1, 2020 18:08
-
-
Save cmol/68f24a39ad9606000cd1994040b0b19c to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def get_interface_info(name) | |
ifaddrs = Socket.getifaddrs.reject do |ifaddr| | |
!ifaddr.addr&.ipv6_linklocal? || (ifaddr.flags & Socket::IFF_MULTICAST == 0) | |
end | |
ifaddrs.select! {|ifaddr| ifaddr.name == name } if name | |
ifaddrs.map {|ifaddr| [ifaddr.name, ifaddr.ifindex, ifaddr.addr.ip_address] } | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment