From: Jim Freeze Date: 2003-09-27T02:02:17+09:00 Subject: Re: TCPSocket.gethostbyname difficulties On Saturday, 27 September 2003 at 1:47:56 +0900, Peter wrote: > > 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 When I run this, I only get the machine name, not the FQDN of my computer: ruby -e "require 'socket'; puts Socket.gethostbyname(Socket.gethostname)[0]" juno ruby -e "require 'socket'; p Socket.gethostbyname(Socket.gethostname)" ["juno", [], 2, "\235_/A"] Is there a way to get the full name? -- Jim Freeze ---------- Your lucky number has been disconnected.