“Joe” == Joe C. firstname.lastname@example.org writes:
Can a ruby on rails app obtain the ip of the server it is running on?
Generally speaking no, it can’t, because there is no such thing as
the IP address of a machine. Even my lowly iMac has two, one for the
Ethernet port and one for the wireless. The main webserver at work has
eight IP adresses, none of which is more important than the others.
I’d like the application to grab the corresponding ip for that url.
Someone had previously suggested using @request.remote_ip, but that
obtains the ip from the requesting address, not the address of the url.
Why do you want that? And why do you even need to figure it out? It’s
your application running on your webserver, why don’t you already
know which IPs it’s listening on?
I’m thinking of using this method:
domain_name = @request.domain
ipaddr = IPSocket.getaddress( domain_name )
Is this my best bet?
Almost certainly not. If they’re your domains, you already have this
information and you’re better off just putting it into a hash for
lookup. If they’re not your domains, you can’t trust that there will
be only one IP for each name.
This whole question looks a whole lot like you have a problem A, and
you think a solution is B. So you ask how to do B. But in reality
there is probably an easier solution C, and B is just a wild goose
chase. You’d probably get more useful answers if you asked about A
Calle D. <email@example.com>
"I'd rather hang on to madness than normality" -- KaTe Bush