I have searched everywhere but their solution requires some form of IP address. Here are the solutions i have found.
require \'socket\'
#METHOD 1
ip
As there is no such thing as a default ip-interface to a host (there does not need to be any ip-interface at all actually) all assumptions regarding nameing are vague, do not necessarily hold.
The value returned by gethostname()
can be defined independently to any ip-setup, so it does not need to reflect a valid host in terms of a hostname which could be resolved to any ip-address.
From the POSIX system's API's view the only reliabe function to test for the availablily of (ip-)interfaces is the function getifaddrs()
, which returns a list of all interfaces along with their parameters.
As it looks as if Ruby's current Socket lib does not provide an interface to it, this (http://rubygems.org/gems/system-getifaddrs) gem based approach does seem to be the only way to go.