Forum: Ruby on Rails Problem with Socket.getaddrinfo inside controller or model

Announcement (2017-05-07): is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see and for other Rails- und Ruby-related community platforms.
E9d3f1a9ded6d6b118dd84467f2278df?d=identicon&s=25 Taro Iwakura (iwakura)
on 2009-02-16 10:55
I am using Rails 2.2.2,
trying to get hostname by IP with code like

require 'socket'
Socket.getaddrinfo('', nil, "AF_INET")

In the rails console it works well and gives me:

[["AF_INET", 0, "", "", 2, 2, 17],
["AF_INET", 0, "", "", 2, 1, 6]]

But, inside model or controller output different:

[["AF_INET", 0, "", "", 2, 2, 17],
["AF_INET", 0, "", "", 2, 1, 6]]

Please help to fix and get hostname by ip inside model.
C1ba14b5b57daf931258448e09c4271c?d=identicon&s=25 mkurlavicius (Guest)
on 2009-03-17 00:17
(Received via mailing list)

There is a method in mongrel gem, mongrel.rb, Mongrel::HttpServer#run
which has a line:


and it seems this changes the global state of the Socket class. So,
basically I did this:

Socket.getaddrinfo(some_ip, nil, "AF_INET")
BasicSocket.do_not_reverse_lookup=true # In case nothing goes wrong
with mongrel :)

Quit annoying stuff, I found it almost accidently, doubt it is
somewhere documented.

On Feb 16, 11:55 am, Taro Iwakura <>
This topic is locked and can not be replied to.