Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Ruby > TCPSocket.gethostbyname difficulties

Reply
Thread Tools

TCPSocket.gethostbyname difficulties

 
 
Nathaniel Talbott
Guest
Posts: n/a
 
      09-25-2003
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

<(><


 
Reply With Quote
 
 
 
 
Yukihiro Matsumoto
Guest
Posts: n/a
 
      09-28-2003
Hi,

In message "TCPSocket.gethostbyname difficulties"
on 03/09/26, "Nathaniel Talbott" <(E-Mail Removed)> 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.

 
Reply With Quote
 
 
 
 
James Britt
Guest
Posts: n/a
 
      09-28-2003
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





 
Reply With Quote
 
Mike Stok
Guest
Posts: n/a
 
      09-28-2003
In article <(E-Mail Removed). jp>,
Yukihiro Matsumoto <(E-Mail Removed)> wrote:
>Hi,
>
>In message "TCPSocket.gethostbyname difficulties"
> on 03/09/26, "Nathaniel Talbott" <(E-Mail Removed)> 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
--
http://www.velocityreviews.com/forums/(E-Mail Removed) | The "`Stok' disclaimers" apply.
http://www.stok.co.uk/~mike/ | GPG PGP Key 1024D/059913DA
(E-Mail Removed) | Fingerprint 0570 71CD 6790 7C28 3D60
http://www.exegenix.com/ | 75D2 9EC4 C1C0 0599 13DA
 
Reply With Quote
 
Yukihiro Matsumoto
Guest
Posts: n/a
 
      09-28-2003
Hi,

In message "Re: TCPSocket.gethostbyname difficulties"
on 03/09/29, James Britt <(E-Mail Removed)> 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.

 
Reply With Quote
 
James Britt
Guest
Posts: n/a
 
      09-29-2003
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



 
Reply With Quote
 
ts
Guest
Posts: n/a
 
      09-29-2003
>>>>> "Y" == Yukihiro Matsumoto <(E-Mail Removed)> 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



 
Reply With Quote
 
Reimer Behrends
Guest
Posts: n/a
 
      09-29-2003
Yukihiro Matsumoto ((E-Mail Removed)) 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


 
Reply With Quote
 
Yukihiro Matsumoto
Guest
Posts: n/a
 
      09-30-2003
Hi,

In message "Re: TCPSocket.gethostbyname difficulties"
on 03/09/30, Reimer Behrends <(E-Mail Removed)> 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.

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Is there any provisions for leaning difficulties in the mcse exams =?Utf-8?B?ZW5ncmhhcnY=?= Microsoft Certification 1 04-14-2005 10:02 AM
NAT On a Stick 2516 config difficulties iram Cisco 2 12-14-2004 11:48 PM
VLAN Difficulties? gallwapa@puyallup.k12.wa.us Cisco 2 12-10-2004 04:58 PM
Access difficulties to new SoHo 91 router Chris Cisco 1 05-23-2004 08:56 AM
Windows exam - study difficulties =?Utf-8?B?RGF2aWQgU3RlaW4=?= MCSD 1 02-23-2004 09:43 PM



Advertisments