Hugh Sasse Staff Elec Eng
2003-02-11 15:50:23 UTC
I am trying to get the fully qualified domain name of a machine in a
way that is posrtable in Ruby.
My very first shot was something like
puts %x{hostname} + '.' + %x{domainname}
but that only works on Unix, and I need it portable across PCs too.
My next shot was:
Socket.gethostname
but this returned a nostname that was not fully qualified, which is
fair enough
Socket.gethostbyname(IPSocket.getaddress(host))
didn't return a fully qualified name either.
Is there a generalised way to do this, or is the assumption that
this is possible for all hosts on the internet somehow false? I
know for hosts not on the internet (192.168.0.0/16 [?]) this could
and probably should fail, but...
I'm trying to take advantage of the portability of ruby here, to
avoid lots of 'case RUBY_PLATFORM ...' code.
Thank you,
Hugh
way that is posrtable in Ruby.
My very first shot was something like
puts %x{hostname} + '.' + %x{domainname}
but that only works on Unix, and I need it portable across PCs too.
My next shot was:
Socket.gethostname
but this returned a nostname that was not fully qualified, which is
fair enough
Socket.gethostbyname(IPSocket.getaddress(host))
didn't return a fully qualified name either.
Is there a generalised way to do this, or is the assumption that
this is possible for all hosts on the internet somehow false? I
know for hosts not on the internet (192.168.0.0/16 [?]) this could
and probably should fail, but...
I'm trying to take advantage of the portability of ruby here, to
avoid lots of 'case RUBY_PLATFORM ...' code.
Thank you,
Hugh