linux - Get IP Address for a specific network interface on Ruby -


i need ip address each of network interfaces. issue standard ruby method socket.ip_address_list returns me adress list, no information interface corresponds ip address.

#<addrinfo: 127.0.0.1> #<addrinfo: 192.168.13.175> #<addrinfo: 172.17.0.1> #<addrinfo: ::1> #<addrinfo: fe80::4685:ff:fe0d:c406%wlan0> 

i looking equivalent of nodejs os.networkinterfaces()[interfacename].

how can know ip address specific network interface?

please let me know if there's way information using ruby 1.9.x

i updated ruby 2.3 version , used socket.getifaddrs (available since ruby 2.1).

require 'socket' addr_infos = socket.getifaddrs addr_infos.each |addr_info|     if addr_info.addr         puts "#{addr_info.name} has address #{addr_info.addr.ip_address}" if addr_info.addr.ipv4?     end end 

output:

$ ruby2.3 getinterfaces.rb  lo has address 127.0.0.1 wlan0 has address 192.168.13.175 docker0 has address 172.17.0.1 

Comments

Popular posts from this blog

mysql - Dreamhost PyCharm Django Python 3 Launching a Site -

java - Sending SMS with SMSLib and Web Services -

java - How to resolve The method toString() in the type Object is not applicable for the arguments (InputStream) -