[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

Re: TCPSocket.gethostbyname difficulties

Peter

9/26/2003 4:48:00 PM

1 Answer

Jim Freeze

9/26/2003 5:02:00 PM

0

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.