Skip to content

Instantly share code, notes, and snippets.

@karlbaillie
Created January 2, 2018 16:02
Show Gist options
  • Save karlbaillie/be6b56d3ee4f5b9a07874ce804d355a8 to your computer and use it in GitHub Desktop.
Save karlbaillie/be6b56d3ee4f5b9a07874ce804d355a8 to your computer and use it in GitHub Desktop.
Get Network Interface by IP with Ruby
#!/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