Getting ServerIP Dynamically

How to get the server Ip address dynamically.

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…

Can you elaborate on what you are trying to accomplish?

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 [email protected]

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 [email protected]

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

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 [email protected]

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

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

On May 22, 1:28 am, mrbless [email protected] wrote:

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…

Posted viahttp://www.ruby-forum.com/.

On May 22, 4:02 am, Mahalingam Mr [email protected]

ok

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