On 11/14/06, Lennon Day-Reynolds <[EMAIL PROTECTED]> wrote:
On 11/14/06, Aaron Johnson <[EMAIL PROTECTED]> wrote:
> Is there an operating system independent way in ruby to determine the
> IP address currently bound to any local ethernet interface?  I would
> like a way to find it that does not require DNS lookup or any network
> query for that matter.  The equivalent of 'ifconfig' for unix and
> 'ipconfig' for windows wrapped up into one line of ruby that doesn't
> use system().  This would help with some cross platform server
> deployment issues.

This is hackish in the extreme, but it's what comes to mind at the moment:

Socket.getaddrinfo(Socket.gethostname, 'www').map {|ainfo| ainfo[3] }.uniq

I tried this and only lo, 127.0.0.1 is returned.   Even though en0 has
another IP address.  I would be ok with this if it returned more than
localhost.  Does it work differently for you? There is not DNS
resolution on the target machine.  I wonder if that has anything to do
with it.

facter uses Resolv.getaddress  and a ton of other stuff to collect
info.  Pretty neat.  Just not returning what I need.  There doesn't
appear to be access to local OS network stats without parsing
'ipconfig' and 'ifconfig', unless I write some C.

Thank you for your ideas,
Aaron
_______________________________________________
PDXRuby mailing list
[email protected]
IRC: #pdx.rb on irc.freenode.net
http://lists.pdxruby.org/mailman/listinfo/pdxruby

Reply via email to