tags:

views:

901

answers:

3

I need to get the fully expanded hostname of the host that my Ruby script is running on. In Perl I've used Sys::Hostname::Long with good results. Google seems to suggest I should use Socket.hostname in ruby, but that's returning just the nodename, not the full hostname.

+1  A: 

This seems to work:

hostname = Socket.gethostbyname(Socket.gethostname).first
dvorak
A: 

Excellent, this was something I was looking for.

A: 

Could be a tad simpler => hostname = Socket.gethostname

charley hine
Socket.gethostname doesn't necessarily return a FQDN.
dvorak