From: Peter Date: 2003-09-27T01:47:56+09:00 Subject: Re: TCPSocket.gethostbyname difficulties > How do I get the full name of the machine that I am on? > My current method involves ifconfig -a to get the IP and > nslookup to get the name. > > Is there a ruby -e one liner to do this? > > (Please forgive me if this is a stupid question.) ruby -e "require 'socket'; puts Socket.gethostbyname(Socket.gethostname)[0]" The extra Socket.gethostbyname(...)[0] is necessary because Socket.gethostname does not (necessarily) give the full hostname. Also if your hostname is listed in your /etc/hosts (or the equivalent under windows) as localhost, Socket#gethostbyname still returns the simple hostname and localhost as alias (Socket.gethostbyname(...)[1] gives the list of aliases). This happened on one machine I tested it on... Peter