From: Eric Hodel Date: 2005-09-20T08:49:39+09:00 Subject: Re: nslookup/config question On 19 Sep 2005, at 13:26, Frank Goodman wrote: > Apologies in advance if this is the wrong place to post, appreciate > any > pointers to the right place if I've polluted the wrong thread > > Specifics: > ruby 1.8.2 (2004-12-25) [i686-linux] > Host: Linux gentoo 2.6.12 > > My linux box does not run a nameserver, as it is a home machine > that I use > for development. I connect to the internet through a Dlink router and > cable-modem. > > When I do a Socket/TCPSocket.gethostbyname call from within ruby, for > "unknown" hosts it returns an array that corresponds to my DynDNS > domain name > with my "public IP address" > > When I run `nslookup` it returns: > > ** server can't find foo.foobar.frt: NXDOMAIN > > With the socket version it is more complicated for me to determine > bad hosts > and I certainly can't do it in a portable way, so I'd like to set > things up so > the Ruby.Socket code returns a proper error. > > I'm guessing this has something to do with my (improper) > configuration of my > system or router. Any help would be appreciated > > I am curious why I would get different behaviours from the Ruby > gethostbyname > and nsslookup which I would imagine should resolve down to a > gethostbyname > call as well. > > Ideas? I don't think this is a ruby issue... $ nslookup foo.foobar.frt Server: 192.168.1.15 Address: 192.168.1.15#53 ** server can't find foo.foobar.frt: NXDOMAIN $ ruby -rsocket -e 'Socket.gethostbyname("foo.foobar.frt")' -e:1:in `gethostbyname': getaddrinfo: hostname nor servname provided, or not known (SocketError) from -e:1 Ruby uses the libc resolver to look up domain names. (I forget if nslookup uses libc or its own builtin resolver... host does under OS X.) Try also the pure-ruby DNS resolver: $ ruby -rresolv -e 'p Resolv.getaddress("foo.foobar.frt")' /usr/local/lib/ruby/1.8/resolv.rb:89:in `getaddress': no address for foo.foobar.frt (Resolv::ResolvError) from /usr/local/lib/ruby/1.8/resolv.rb:39:in `getaddress' from -e:1 -- Eric Hodel - drbrain@segment7.net - http://segment7.net FEC2 57F1 D465 EB15 5D6E 7C11 332A 551C 796C 9F04