[lnkForumImage]
TotalShareware - Download Free Software

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


 

Forums >

comp.lang.ruby

get host by addr

Nikos Kanellopoulos

8/11/2007 10:00:00 PM

Hello everybody.
I am trying to do something simple.
I have an IP address and need to do a reverse DNS lookup.
However, I consistently get a "host not found" error.
I have tried this in at least 2 different machines.

What am I doing wrong?

nk@livaditis: ~ $ irb
irb(main):001:0> require 'socket'
=> true
irb(main):002:0> Socket.gethostbyaddr("75.126.252.65")
SocketError: host not found
from (irb):2:in `gethostbyaddr'
from (irb):2
from :0

1 Answer

Nikos Kanellopoulos

8/11/2007 10:57:00 PM

0

2007/8/12, Felix Windt <fwmailinglists@gmail.com>:
> > -----Original Message-----
> > From: Nikos Kanellopoulos [mailto:kanellopoulos.nikos@gmail.com]
> > Sent: Saturday, August 11, 2007 3:00 PM
> > To: ruby-talk ML
> > Subject: get host by addr
> >
> > Hello everybody.
> > I am trying to do something simple.
> > I have an IP address and need to do a reverse DNS lookup.
> > However, I consistently get a "host not found" error.
> > I have tried this in at least 2 different machines.
> >
> > What am I doing wrong?
> >
> > nk@livaditis: ~ $ irb
> > irb(main):001:0> require 'socket'
> > => true
> > irb(main):002:0> Socket.gethostbyaddr("75.126.252.65")
> > SocketError: host not found
> > from (irb):2:in `gethostbyaddr'
> > from (irb):2
> > from :0
> >
>
>
> irb(main):001:0> require 'socket'
> => true
> irb(main):002:0> Socket.getaddrinfo('75.126.252.65', nil)
> => [["AF_INET", 0, "75.126.252.65-static.reverse.softlayer.com",
> "75.126.252.65", 2, 1, 6], ["AF_INET", 0,
> "75.126.252.65-static.reverse.softlayer.com", "75.126.252.65", 2, 2, 17],
> ["AF_INET", 0, "75.126.252.65-static.reverse.softlayer.com",
> "75.126.252.65", 2, 3, 0]]
> irb(main):003:0>
>
>

Nice! This works fine in irb.
However, it fails to do the reverse lookup from within my rails application.
It just returns the IP as the host name. Strange...