Getting ServerIP Dynamically

How to get the server Ip address dynamically.

Can you elaborate on what you are trying to accomplish?

Mr. Bless wrote:

How to get the server Ip address dynamically.

what operating system do u use?...do u have a dhcp server in your
network?

if you have a dhcp server and your server operating system is linux,
then type

dhclient in the terminal...it will fetch you a ip address dynamically...

I am using window. My requirement is to send the email with the link
including activation code when the user sign up for an account. Right
now it sends http://localhost:3000/activation_code now I want to
include server ip address instead of localhost

mrbless wrote:

I am using window. My requirement is to send the email with the link
including activation code when the user sign up for an account. Right
now it sends http://localhost:3000/activation_code now I want to
include server ip address instead of localhost

On May 22, 12:28 pm, Mahalingam Mr <rails-mailing-l...@andreas-s.net>

if the server is in windows look for the httpd.conf file in it & edit
the servername from localhost to your servers ip address..

Mahalingam Mr wrote:

mrbless wrote:

I am using window. My requirement is to send the email with the link
including activation code when the user sign up for an account. Right
now it sends http://localhost:3000/activation_code now I want to
include server ip address instead of localhost

On May 22, 12:28 pm, Mahalingam Mr <rails-mailing-l...@andreas-s.net>

if the server is in windows look for the httpd.conf file in it & edit
the servername from localhost to your servers ip address..

I believe the original poster is wanting to know how to do it
dynamically. I use the following method to build URLs:

  require 'ipaddr'

  def wgg_build_url(resource)
    begin
      ip = IPAddr.new(request.host)
    rescue
      ip = nil
    end

    root_url =
      if ip && ip.ipv4?
        "#{request.protocol}#{request.host}#{request.port_string}"
      else
        sub_domain = request.subdomains.first ?
"#{request.subdomains.first}." : ''
        "#{request.protocol}#{sub_domain}#{request.domain}#{request.port_string}"
      end

    resource[0] = '' if resource.at(0) == '/'
    return "#{root_url}/#{resource}"
  end

It's something I wrote, so feel free to use it, rename it, change it,
whatever.

Peace,
Phillip

Okay I hate to ask for more details but the server ip address can be
several things. First of all the IP address that your RoR web server
is binding to may not be the correct IP address depending on what you
are trying to do. If you are going to access your web server from your
internal network, then yes the IP address that your RoR web server is
binding to will most likely be the correct one. However, if your web
server is serving requests to the outside (for example, to others on
the internet) you will most likely have a different "server" IP
address that is provided to you by your ISP (this would be your public
IP address). Then you must make sure that you have the appropriate
port mapping rules (eg. firewall rules) that will route port 80 (or
any port like 3000) on the public IP address to your computer's IP
address's port 3000 that is running the RoR web server.

In either case, if you are using apache I would change the
'servername' (also suggested by Mahalingam) to the either one of the
two possible IP address I mentioned above, either the local computer's
internal IP address or the public IP address.

Thanks,
Gregg

Thanks alot Guys for your time and suggestion. Thank you...

ok