TCPSocket.gethostbyname difficulties

N

Nathaniel Talbott

I'm trying to use TCPSocket.gethostbyname to verify that a given domain
actually exists in DNS. For some reason, though, some domains fail to
resolve that resolve fine using other applications. For instance:

irb(main):001:0> require 'socket'
=> true
irb(main):002:0> TCPSocket.gethostbyname('noblepack.com')
SocketError: host not found
from (irb):2:in `gethostbyname'
from (irb):2
irb(main):003:0> TCPSocket.gethostbyname('google.com')
=> ["www.google.com", [], 2, "216.239.37.100"]

I can browse to either of those hosts, so what's different about them? Any
help would be greatly appreciated; my guess is that I just fail to
understand something critical about DNS and/or gethostbyname.

Thanks,


Nathaniel

<:((><
 
Y

Yukihiro Matsumoto

Hi,

In message "TCPSocket.gethostbyname difficulties"

|I'm trying to use TCPSocket.gethostbyname to verify that a given domain
|actually exists in DNS. For some reason, though, some domains fail to
|resolve that resolve fine using other applications. For instance:
|
| irb(main):001:0> require 'socket'
| => true
| irb(main):002:0> TCPSocket.gethostbyname('noblepack.com')
| SocketError: host not found
| from (irb):2:in `gethostbyname'
| from (irb):2

This works for me:

ruby -r socket -e 'p TCPSocket.gethostbyname("noblepack.com")'
ruby 1.8.0 (2003-09-27) [i686-linux]
["noblepack.com", [], 2, "205.178.141.161"]

Could you tell us more info?

matz.
 
J

James Britt

Yukihiro said:
This works for me:

ruby -r socket -e 'p TCPSocket.gethostbyname("noblepack.com")'
ruby 1.8.0 (2003-09-27) [i686-linux]
["noblepack.com", [], 2, "205.178.141.161"]

Could you tell us more info?

Out of curiosity, I just tried the above, on my Win2k laptop, running
/\ndy's 1.8 build:

C:\>ruby -v
ruby 1.8.0 (2003-08-04) [i386-mswin32]

C:\> ruby -r socket -e 'p TCPSocket.gethostbyname("noblepack.com")'
-e:1:in `gethostbyname': host not found (SocketError)
from -e:1

However, I can ping that location just fine.

I then tried a different address:

C:\> ruby -r socket -e 'p TCPSocket.gethostbyname("jamesbritt.com")'
["amsnac3.com", [], 2, "66.246.52.127"]



James Britt
 
M

Mike Stok

Hi,

In message "TCPSocket.gethostbyname difficulties"

|I'm trying to use TCPSocket.gethostbyname to verify that a given domain
|actually exists in DNS. For some reason, though, some domains fail to
|resolve that resolve fine using other applications. For instance:
|
| irb(main):001:0> require 'socket'
| => true
| irb(main):002:0> TCPSocket.gethostbyname('noblepack.com')
| SocketError: host not found
| from (irb):2:in `gethostbyname'
| from (irb):2

This works for me:

ruby -r socket -e 'p TCPSocket.gethostbyname("noblepack.com")'
ruby 1.8.0 (2003-09-27) [i686-linux]
["noblepack.com", [], 2, "205.178.141.161"]

Could you tell us more info?

Although not addressed to me, on Mandrake Linux 9.1 I see

[mike@ratdog mike]$ ruby -v -r socket -e 'p TCPSocket.gethostbyname("noblepack.com")'
ruby 1.8.0 (2003-09-27) [i686-linux]
-e:1:in `gethostbyname': host not found (SocketError)
from -e:1
[mike@ratdog mike]$ ping -c 1 noblepack.com
PING noblepack.com (205.178.141.161) 56(84) bytes of data.
64 bytes from 205.178.141.161: icmp_seq=1 ttl=119 time=52.9 ms

--- noblepack.com ping statistics ---
1 packets transmitted, 1 received, 0% packet loss, time 0ms
rtt min/avg/max/mdev = 52.996/52.996/52.996/0.000 ms
[mike@ratdog mike]$ ruby -v -r socket -e 'p TCPSocket.gethostbyname("stok.co.uk")'
ruby 1.8.0 (2003-09-27) [i686-linux]
["berke-breathed.deathtongue.org", [], 2, "209.251.75.53"]

Hope this helps,

Mike
 
Y

Yukihiro Matsumoto

Hi,

In message "Re: TCPSocket.gethostbyname difficulties"

|Out of curiosity, I just tried the above, on my Win2k laptop, running
|/\ndy's 1.8 build:
|
|C:\>ruby -v
|ruby 1.8.0 (2003-08-04) [i386-mswin32]
|
|C:\> ruby -r socket -e 'p TCPSocket.gethostbyname("noblepack.com")'
|-e:1:in `gethostbyname': host not found (SocketError)
| from -e:1
|
|However, I can ping that location just fine.

Hmm, might be Win32 specific problem. Does stopping reverse lookup
make any difference?

Socket.do_not_reverse_lookup = false

matz.
 
J

James Britt

Yukihiro said:
Hmm, might be Win32 specific problem. Does stopping reverse lookup
make any difference?
Socket.do_not_reverse_lookup = false

No. Same results.

James
 
T

ts

Y> Socket.do_not_reverse_lookup = false

If I'm right ruby don't use it in this case, perhaps a good idea to add
this test.

svg% host noblepack.com
noblepack.com has address 205.178.141.161
svg%

svg% host 205.178.141.161
Host 161.141.178.205.in-addr.arpa not found: 3(NXDOMAIN)
svg%



Guy Decoux
 
R

Reimer Behrends

Yukihiro Matsumoto ([email protected]) wrote:
[...]
This works for me:

ruby -r socket -e 'p TCPSocket.gethostbyname("noblepack.com")'
ruby 1.8.0 (2003-09-27) [i686-linux]
["noblepack.com", [], 2, "205.178.141.161"]

Could you tell us more info?

This surprises me, since there is no PTR record for 205.178.141.161,
and ruby (1.8.0 in my case) insists on doing a gethostbyaddr() on
that address (in sock_hostbyname()) and will raise a "host not
found" error if gethostbyaddr() fails (usually if there is no PTR
record). That lookup is performed regardless of the value of
Socket.do_not_reverse_lookup.

Incidentally, what is the rationale behind requiring the presence of
a PTR record? There are many hosts that do not have one, especially
virtual web hosts, and I have found Socket/TCPSocket.gethostbyname to be
fairly useless as a result (and instead resorted to using
Resolv.getaddress[es]).

Reimer Behrends
 
Y

Yukihiro Matsumoto

Hi,

In message "Re: TCPSocket.gethostbyname difficulties"

|This surprises me, since there is no PTR record for 205.178.141.161,
|and ruby (1.8.0 in my case) insists on doing a gethostbyaddr() on
|that address (in sock_hostbyname()) and will raise a "host not
|found" error if gethostbyaddr() fails (usually if there is no PTR
|record). That lookup is performed regardless of the value of
|Socket.do_not_reverse_lookup.
|
|Incidentally, what is the rationale behind requiring the presence of
|a PTR record? There are many hosts that do not have one, especially
|virtual web hosts, and I have found Socket/TCPSocket.gethostbyname to be
|fairly useless as a result (and instead resorted to using
|Resolv.getaddress[es]).

Ah, thanks. Your message reminds me Ruby's gethostbyname method is
implemented by the combination of getaddrinfo() and gethostbyaddr().
The reason behind this is plain gethostbyname() does not work well
with IPv6 addresses (on some platforms). I want to fix this, but I
don't know how (yet).

matz.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,764
Messages
2,569,565
Members
45,041
Latest member
RomeoFarnh

Latest Threads

Top