On 2 Mar 2000, Dave Thomas wrote: > Hugh Sasse Staff Elec Eng <hgs / dmu.ac.uk> writes: > > > gethostbyname seems to be a method of IPSocket and Socket only. > > What is the correct way to invoke it in ruby? Everything I have tried > > tells me thee is no data for the machine I am on, although nslookup > > shows its existence correctly. > > There's TCPSocket.gethostbyname() and TCPSocket.getaddress(). and they both fail for me: atlanta hgs 291 %> ./!$ ./hostname2.rb PATH /usr/ucb:/bin this host is atlanta ./hostname2.rb:17:in `getaddress': no address associated with hostname. (SocketError) from ./hostname2.rb:17 atlanta hgs 292 %> cat hostname2.rb #!/usr/local/bin/ruby -T #Author: Hugh Sasse <hgs / dmu.ac.uk> #Started: 02-MAR-1999 # ENV['PATH'] = "/usr/ucb:/bin" require "socket" print "PATH #{ENV['PATH']} \n" thishost = `hostname` print "this host is #{thishost}\n" address = TCPSocket.getaddress(thishost) print "this host has address #{address}" atlanta hgs 293 %> ... atlanta hgs 295 %> diff -c hostname2.rb hostname3.rb *** hostname2.rb Thu Mar 2 15:34:48 2000 --- hostname3.rb Thu Mar 2 15:38:08 2000 *************** *** 14,20 **** print "this host is #{thishost}\n" ! address = TCPSocket.getaddress(thishost) print "this host has address #{address}" --- 14,20 ---- print "this host is #{thishost}\n" ! address = TCPSocket.gethostbyname(thishost) print "this host has address #{address}" atlanta hgs 296 %> ./!$ ./hostname3.rb PATH /usr/ucb:/bin this host is atlanta ./hostname3.rb:17:in `gethostbyname': no address associated with hostname. (SocketError) from ./hostname3.rb:17 atlanta hgs 297 %> ruby -v ruby 1.4.3 (1999-12-08) [sparc-solaris2.5.1] atlanta hgs 298 %> > > Dave > Hugh hgs / dmu.ac.uk