[lnkForumImage]
TotalShareware - Download Free Software

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


 

Forums >

comp.lang.ruby

TCPSocket.gethostbyname difficulties

Nathaniel Talbott

9/25/2003 8:48:00 PM

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

<:((><


8 Answers

matz

9/28/2003 2:26:00 PM

0

Hi,

In message "TCPSocket.gethostbyname difficulties"
on 03/09/26, "Nathaniel Talbott" <nathaniel@NOSPAMtalbott.ws> writes:

|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.

James Britt

9/28/2003 3:40:00 PM

0

Yukihiro Matsumoto 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?

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





mike

9/28/2003 10:06:00 PM

0

In article <1064759167.506592.9057.nullmailer@picachu.netlab.jp>,
Yukihiro Matsumoto <matz@ruby-lang.org> wrote:
>Hi,
>
>In message "TCPSocket.gethostbyname difficulties"
> on 03/09/26, "Nathaniel Talbott" <nathaniel@NOSPAMtalbott.ws> writes:
>
>|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
--
mike@stok.co.uk | The "`Stok'' disclaimers" apply.
http://www.stok.co... | GPG PGP Key 1024D/059913DA
mike@exegenix.com | Fingerprint 0570 71CD 6790 7C28 3D60
http://www.exe... | 75D2 9EC4 C1C0 0599 13DA

matz

9/28/2003 11:15:00 PM

0

Hi,

In message "Re: TCPSocket.gethostbyname difficulties"
on 03/09/29, James Britt <jamesUNDERBARb@seemyemail.com> writes:

|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.

James Britt

9/29/2003 12:27:00 AM

0

Yukihiro Matsumoto wrote:

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

No. Same results.

James



ts

9/29/2003 8:41:00 AM

0

>>>>> "Y" == Yukihiro Matsumoto <matz@ruby-lang.org> writes:

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



Reimer Behrends

9/29/2003 8:30:00 PM

0

Yukihiro Matsumoto (matz@ruby-lang.org) 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


matz

9/30/2003 9:35:00 AM

0

Hi,

In message "Re: TCPSocket.gethostbyname difficulties"
on 03/09/30, Reimer Behrends <behrends@cse.msu.edu> writes:

|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.