Erwin
2008-Dec-11 17:03 UTC
how do I get the host or Ip address where my rails app is running
Hi I would like to get in a variable the ip address of the host where my app is running, to change some parameters if it''s running locally or remotely .. is it possible ? I cannot use request.host, since there is no request yet I suppose I should test it in application.rb, not in environment.rb during initialization .. thanks for your suggestions .. erwin --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Mark Reginald James
2008-Dec-11 23:21 UTC
Re: how do I get the host or Ip address where my rails app is running
Erwin wrote:> I would like to get in a variable the ip address of the host where my > app is running, to change some parameters if it''s running locally or > remotely .. is it possible ?You can try require ''socket'' REAL_PRODUCTION = Socket.gethostname == ''mysite.com'' or hostinfo = Socket.gethostbyname(Socket.gethostname) hostnames = hostinfo[1] << hostinfo[0] REAL_PRODUCTION = hostnames.include?(''mysite.com'') -- Rails Wheels - Find Plugins, List & Sell Plugins - http://railswheels.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 -~----------~----~----~----~------~----~------~--~---
Quee WM
2010-Jan-08 16:16 UTC
Re: how do I get the host or Ip address where my rails app i
Mark Reginald James wrote:> You can try > > require ''socket'' > REAL_PRODUCTION = Socket.gethostname == ''mysite.com'' > > or > > hostinfo = Socket.gethostbyname(Socket.gethostname) > hostnames = hostinfo[1] << hostinfo[0] > REAL_PRODUCTION = hostnames.include?(''mysite.com'') > > -- > Rails Wheels - Find Plugins, List & Sell Plugins - > http://railswheels.comThis returns the hostname from the box where the site is running which can help as well but is there a way to get the ip of the box? I have tried to mirror two different servers this way i can test on one and deploy on the other and also keep the other as a backup should i ever need to redeploy to the other so the hostname and all are the same. (this maybe wrong way to do things so you may correct me)... So my issue comes that the hostname is same on both machines and only the ip will do. -- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Sijo k g
2010-Jan-08 18:21 UTC
Re: how do I get the host or Ip address where my rails app is running
Hi Kad Kerforn require ''ipaddr'' require ''net/http'' def get_ip con = Net::HTTP.new(''checkip.dyndns.org'', 80) resp,body = con.get("/", nil) ip = body.match(/\d+\.\d+\.\d+\.\d+/) ip[0] end my_ip = IPAddr.new(get_ip) Sijo -- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Quee WM
2010-Jan-08 18:43 UTC
Re: how do I get the host or Ip address where my rails app i
Thanks Sijo. This will help a lot. Sijo k g wrote:> Hi Kad Kerforn > require ''ipaddr'' > require ''net/http'' > def get_ip > con = Net::HTTP.new(''checkip.dyndns.org'', 80) > resp,body = con.get("/", nil) > ip = body.match(/\d+\.\d+\.\d+\.\d+/) > > ip[0] > end > my_ip = IPAddr.new(get_ip)-- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.