Last active
November 2, 2020 17:18
-
-
Save Beyarz/64cf6f59c2faf67b356cd742d5b0f928 to your computer and use it in GitHub Desktop.
Get your interface and the ip assigned to it
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
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