whats the best way to get a client ip address. I am using rails if that
makes any difference
···
--
Posted via http://www.ruby-forum.com/.
whats the best way to get a client ip address. I am using rails if that
makes any difference
--
Posted via http://www.ruby-forum.com/.
If you are using rails then this should get you going.
ip_addr = request.env['REMOTE_ADDR']
cheers
On 2/12/07, Stewart <smathe2@hotmail.com> wrote:
whats the best way to get a client ip address. I am using rails if that
makes any difference--
Posted via http://www.ruby-forum.com/\.
Stewart wrote:
whats the best way to get a client ip address. I am using rails if that
makes any difference
It does - you need the socket, and if you're in a Mongrel hiding behind
an Apache or IIS you're out of luck. Otherwise, BasicSocket::getpeeraddr
is what you want - then you have to parse the sockaddr structure in a
platform-dependent way. Blech - why can't Ruby do basic sockets right?
Stewart wrote:
whats the best way to get a client ip address. I am using rails if that
makes any difference
Use the remote_ip method of the request object. It looks for forwarded
requests automatically:
http://api.rubyonrails.org/classes/ActionController/AbstractRequest.html#M000408
--
Posted via http://www.ruby-forum.com/\.
Clifford Heath wrote:
Stewart wrote:
whats the best way to get a client ip address. I am using rails if that
makes any differenceIt does - you need the socket, and if you're in a Mongrel hiding behind
an Apache or IIS you're out of luck. Otherwise, BasicSocket::getpeeraddr
is what you want - then you have to parse the sockaddr structure in a
platform-dependent way. Blech - why can't Ruby do basic sockets right?
If you're please behind a mongrel cluster you can use
request.env['HTTP_X_FORWARDED_FOR'].split(", ")
the first element in the resultant array should be the originating
client IP address
--
Posted via http://www.ruby-forum.com/\.