Skip to content

Instantly share code, notes, and snippets.

@cmol
Last active October 1, 2020 18:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cmol/68f24a39ad9606000cd1994040b0b19c to your computer and use it in GitHub Desktop.
Save cmol/68f24a39ad9606000cd1994040b0b19c to your computer and use it in GitHub Desktop.
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