Taro Iwakura
2009-Feb-16 09:55 UTC
Problem with Socket.getaddrinfo inside controller or model
I am using Rails 2.2.2, trying to get hostname by IP with code like require ''socket'' Socket.getaddrinfo(''221.186.184.68'', nil, "AF_INET") In the rails console it works well and gives me: [["AF_INET", 0, "carbon.ruby-lang.org", "221.186.184.68", 2, 2, 17], ["AF_INET", 0, "carbon.ruby-lang.org", "221.186.184.68", 2, 1, 6]] But, inside model or controller output different: [["AF_INET", 0, "221.186.184.68", "221.186.184.68", 2, 2, 17], ["AF_INET", 0, "221.186.184.68", "221.186.184.68", 2, 1, 6]] Please help to fix and get hostname by ip inside model. -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
mkurlavicius
2009-Mar-16 20:39 UTC
Re: Problem with Socket.getaddrinfo inside controller or model
Hi, There is a method in mongrel gem, mongrel.rb, Mongrel::HttpServer#run which has a line: BasicSocket.do_not_reverse_lookup=true and it seems this changes the global state of the Socket class. So, basically I did this: BasicSocket.do_not_reverse_lookup=false 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 <rails-mailing-l...-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:> I am using Rails 2.2.2, > trying to get hostname by IP with code like > > require ''socket''Socket.getaddrinfo(''221.186.184.68'', nil, "AF_INET") > > In the rails console it works well and gives me: > > [["AF_INET", 0, "carbon.ruby-lang.org", "221.186.184.68", 2, 2, 17], > ["AF_INET", 0, "carbon.ruby-lang.org", "221.186.184.68", 2, 1, 6]] > > But,insidemodelorcontrolleroutput different: > > [["AF_INET", 0, "221.186.184.68", "221.186.184.68", 2, 2, 17], > ["AF_INET", 0, "221.186.184.68", "221.186.184.68", 2, 1, 6]] > > Please help to fix and get hostname by ipinsidemodel. > -- > Posted viahttp://www.ruby-forum.com/.--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---