Skip to content

Instantly share code, notes, and snippets.

@Beyarz
Last active November 2, 2020 17:18
Show Gist options
  • Save Beyarz/64cf6f59c2faf67b356cd742d5b0f928 to your computer and use it in GitHub Desktop.
Save Beyarz/64cf6f59c2faf67b356cd742d5b0f928 to your computer and use it in GitHub Desktop.
Get your interface and the ip assigned to it
require "socket"
require "ipaddr"
getifaddr = Socket.getifaddrs
getifaddr.each do | interface |
if interface.addr
if interface.addr.ipv4?
puts interface.name, interface.addr.ip_address
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment