Created
January 2, 2018 16:02
-
-
Save karlbaillie/be6b56d3ee4f5b9a07874ce804d355a8 to your computer and use it in GitHub Desktop.
Get Network Interface by IP with Ruby
This file contains hidden or 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
#!/home/kbaillie/.rbenv/shims/ruby | |
node_ip = "192.168.1.1" | |
require 'socket' | |
addr_infos = Socket.getifaddrs | |
addr_infos.each do |addr_info| | |
next unless addr_info.addr.ipv4? | |
if node_ip == addr_info.addr.ip_address | |
puts "#{addr_info.name}" | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment