[lnkForumImage]
TotalShareware - Download Free Software

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


 

Forums >

comp.lang.ruby

Re: TCPSocket.gethostbyname difficulties

Nathaniel Talbott

9/26/2003 1:49:00 PM

ts [mailto:decoux@moulon.inra.fr] wrote:

> N> I'm trying to use TCPSocket.gethostbyname to verify that a given
> N> domain actually exists in DNS.
>
> you can't, just try
>
> moulon% host xxxxyyyyttttuuu.com
> xxxxyyyyttttuuu.com has address 64.94.110.11
> moulon%
>
> moulon% host aaazertyuiop.com
> aaazertyuiop.com has address 64.94.110.11
> moulon%

Right, this is due to Verisign's irritating site-finder thingy, but I can
filter those results out if I want to. What about the following, though:

ntalbott@proxytest:~$ host cancer.org
cancer.org has address 209.135.47.118
cancer.org has address 0.0.0.0
ntalbott@proxytest:~$ ruby -rsocket -e 'p
TCPSocket::gethostbyname("cancer.org")'
-e:1:in `gethostbyname': host not found (SocketError)
from -e:1

Can I make that work?


Nathaniel

<:((><


6 Answers

ts

9/26/2003 1:53:00 PM

0

>>>>> "N" == Nathaniel Talbott <nathaniel@NOSPAMtalbott.ws> writes:

N> ntalbott@proxytest:~$ host cancer.org
N> cancer.org has address 209.135.47.118
N> cancer.org has address 0.0.0.0

Why do you want to work with something which is broken ?

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



Guy Decoux

Rob Partington

9/27/2003 2:13:00 PM

0

On Fri, 26 Sep 2003 22:53:24 +0900,
ts <decoux@moulon.inra.fr> wrote:
> Why do you want to work with something which is broken ?

Since when did the lack of reverse mean that forward lookups were broken?

This is something that''s broken with *Ruby* (like I pointed out nearly two
years ago) and should have been fixed by now.

ts

9/27/2003 2:35:00 PM

0

>>>>> "R" == Rob Partington <rjp@frottage.org> writes:

R> On Fri, 26 Sep 2003 22:53:24 +0900,
R> ts <decoux@moulon.inra.fr> wrote:
>> Why do you want to work with something which is broken ?

R> Since when did the lack of reverse mean that forward lookups were broken?

Why you don''t quote completely the message. You find this normal ?

svg% host cancer.org
cancer.org has address 0.0.0.0
cancer.org has address 209.135.47.118
svg%


Guy Decoux

Rob Partington

9/28/2003 7:22:00 AM

0

On Sat, 27 Sep 2003 23:34:54 +0900,
ts <decoux@moulon.inra.fr> wrote:
>R> Since when did the lack of reverse mean that forward lookups were broken?
> Why you don''t quote completely the message. You find this normal ?
>
> svg% host cancer.org
> cancer.org has address 0.0.0.0
> cancer.org has address 209.135.47.118
> svg%

*sigh* No, that''s not normal, but you then demonstrated that it had no
reverse -- seemingly to make your point. My apologies if I misunderstood,
but the fact remains that Ruby''s gethostbyname *is* seriously broken and
won''t look up hostnames that have no reverse, "broken" or not.

For example, rotten.com can''t be looked up using Ruby and isn''t "broken".

> host rotten.com
rotten.com has address 216.218.248.174
> host 216.218.248.174
Host not found.
> irb
irb(main):001:0> require ''socket''
=> true
irb(main):002:0> Socket::gethostbyname(''rotten.com'')
SocketError: host not found
from (irb):2:in `gethostbyname''
from (irb):2

We already know that the "broken" cancer.org doesn''t work.

irb(main):003:0> Socket::gethostbyname(''cancer.org'')
SocketError: host not found
from (irb):3:in `gethostbyname''
from (irb):3

But getaddrinfo does work, though requires you to specify a service name.

irb(main):007:0> Socket::getaddrinfo(''rotten.com'', ''http'')
=> [["AF_INET", 80, "216.218.248.174", "216.218.248.174", 2, 2, 17],
["AF_INET", 80, "216.218.248.174", "216.218.248.174", 2, 1, 6]]

Broken it might be, but Ruby is still able to look up cancer.org''s A records
with no trouble if you use getaddrinfo.

irb(main):009:0> Socket::getaddrinfo(''cancer.org'', ''http'')
=> [["AF_INET", 80, "0.0.0.0", "0.0.0.0", 2, 2, 17], ["AF_INET", 80,
"209.135.47.118", "209.135.47.118", 2, 2, 17], ["AF_INET", 80,
"209.135.47.118", "209.135.47.118", 2, 1, 6], ["AF_INET", 80, "0.0.0.0",
"0.0.0.0", 2, 1, 6]]

Lest you think it''s not Ruby''s fault, both work fine with Perl.

> perl -e ''print join(".", unpack("C4", (gethostbyname("rotten.com"))[4]))''
216.218.248.174
perl -e ''print join(".", unpack("C4", (gethostbyname("cancer.org"))[4])),"\n"''
209.135.47.118

They also work fine in Python.

>>> import socket
>>> socket.gethostbyname("rotten.com")
''216.218.248.174''
>>> socket.gethostbyname("cancer.org")
''209.135.47.118''

Why does Ruby persist in this nonsense? People will expect gethostbyname to
Just Work since it does everywhere else. I posted RCR#46 about this bug
almost two years ago now and, it seems, people are still having problems
with it. Maybe it''s time to fix it finally?

RCR#46 lives at http://www.rubygarden.org/article.p...

ts

9/28/2003 12:10:00 PM

0

>>>>> "R" == Rob Partington <rjp@frottage.org> writes:

R> For example, rotten.com can''t be looked up using Ruby and isn''t "broken".

svg% ruby -rsocket -e ''p IPSocket.getaddress("rotten.com")''
"216.218.248.174"
svg%

svg% ruby -rsocket -e ''3.times { p IPSocket.getaddress("cancer.org") }''
"0.0.0.0"
"209.135.47.118"
"0.0.0.0"
svg%


Guy Decoux

Rob Partington

9/28/2003 3:55:00 PM

0

On Sun, 28 Sep 2003 21:10:03 +0900,
ts <decoux@moulon.inra.fr> wrote:
>>>>>> "R" == Rob Partington <rjp@frottage.org> writes:
>R> For example, rotten.com can''t be looked up using Ruby and isn''t "broken".
> svg% ruby -rsocket -e ''p IPSocket.getaddress("rotten.com")''
> "216.218.248.174"

Yes, I already showed that getaddrinfo worked fine. gethostbyname *doesn''t*.

http://www.c2.com/cgi/wiki?FixBro... sums it up quite well. That this
is still confusing people *two years later* is insane.