Hi, basically I'm looking for a way to find all the IP's in the
network interfaces of my computer in a reliable way.
I know a "workaround":
···
--------------------------
UDPSocket.open {|s| s.connect "1.2.3.4", 80; s.addr }
---------------------------
=> ["AF_INET", 33564, "192.168.1.16", "192.168.1.16"]
But this method knows nothing about other IP's in the same interface,
neither allows me to discover other IP's in other interfaces with
different routes.
Is there something as "ifconfig" or "ip addr show" commands for Ruby?
Thanks a lot.
--
Iñaki Baz Castillo
<ibc@aliax.net>
I got another way:
Socket::getaddrinfo(Socket.gethostname, "echo", Socket::AF_INET).map
{ |x| x[3] }
=> ["127.0.0.1", "127.0.0.1", "127.0.1.1", "127.0.1.1",
"192.168.1.16", "192.168.1.16"]
Not very cool, but...
PS: There is also a ruby-ifconfig library, not available via gem it seems.
···
2011/5/11 Iñaki Baz Castillo <ibc@aliax.net>:
Hi, basically I'm looking for a way to find all the IP's in the
network interfaces of my computer in a reliable way.
I know a "workaround":
--------------------------
UDPSocket.open {|s| s.connect "1.2.3.4", 80; s.addr }
---------------------------
=> ["AF_INET", 33564, "192.168.1.16", "192.168.1.16"]
But this method knows nothing about other IP's in the same interface,
neither allows me to discover other IP's in other interfaces with
different routes.
--
Iñaki Baz Castillo
<ibc@aliax.net>
Hi, basically I'm looking for a way to find all the IP's in the
network interfaces of my computer in a reliable way.
<snip>
Is there something as "ifconfig" or "ip addr show" commands for Ruby?
Thanks a lot.
in Ruby 1.9.2:
require 'socket'
Socket.ip_address_list
···
Iñaki Baz Castillo <ibc@aliax.net> wrote:
--
Eric Wong
Amazing! I knew nothing about it 
Thanks a lot.
···
2011/5/11 Eric Wong <normalperson@yhbt.net>:
Is there something as "ifconfig" or "ip addr show" commands for Ruby?
Thanks a lot.
in Ruby 1.9.2:
require 'socket'
Socket.ip_address_list
--
Iñaki Baz Castillo
<ibc@aliax.net>