How to capture IP address in ruby 1.8.7

Hi all, I want to capture IP address in ruby 1.8.7 can any one help me out how to capture IP.

Thanks in advance

I have tried with request.remote_ip.But this works in rails not in ruby. I have to pass ip address as a parameter.

How about using request.remote_addr ?

Thanks Rafi for your reply but can I use request.remore_addr directly like

ip = request.remote_addr in ruby. it is saying undefined request local vairable.

Can you copy your ruby script ?

Regards,
Logan

The controller is intended to handle things related to the request and response. Are you trying this out when you are inside the model?? If so, then you can’t access the request inside model.

ip = request.remote_addr
NameError: undefined local variable or method `request’ for #Object:0xb785f950
from (irb):1

Which I am getting in irb.

You cannot get this value in irb… Controller only intended to handle the request & response. Can you try that in some controller method?

ok Rafi Thank you

Hey Khan.

Here you have some examples:

http://stackoverflow.com/questions/14112955/how-to-get-my-machines-ip-address-from-ruby-without-leveraging-from-other-ip-ad