getting client ip address

S

Stewart

whats the best way to get a client ip address. I am using rails if that
makes any difference
 
C

Clifford Heath

Stewart said:
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?
 
J

John O'gara

Clifford said:
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?

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top