Geo-location using the GeoIp plugin

Hi,
For my upcoming application I need to find the location of the user.
I am doing this by using the “GeoIp” plugin.
For geoIp I have to find the IP address of the incoming request.
I have written the code to get the IP address:-
“client_ipaddress=request.env[“HTTP_X_FORWARDED_FOR”] ||
request.remote_addr”
But it is giving me the IP address of the machine. Is it right?
If yes then how the GeoIp will find the location of the machine.
I have tried some online demo’s which actually detect the IP address of
the router and depending on that they are finding the location.

Can anyone tell me Am I on right path?

Thanks,
Tushar

Hey Tushar,

Try changing HTTP_X_FORWARDED_FOR to REMOTE_ADDR. The second one of
those is what will give you the user’s IP address. Bear in mind that
if they’re behind a proxy, you’ll get the IP address of that proxy
instead of theirs, but then again, that’s one of the points of their
using a proxy to begin with :slight_smile:

Good luck!

On Feb 25, 2011, at 8:31 AM, Phoenix R. wrote:

Try changing HTTP_X_FORWARDED_FOR to REMOTE_ADDR. The second one of
those is what will give you the user’s IP address. Bear in mind that
if they’re behind a proxy, you’ll get the IP address of that proxy
instead of theirs, but then again, that’s one of the points of their
using a proxy to begin with :slight_smile:

I just ran afoul of this when trying to pay my insurance bill. The
poorly-written sniffer on the insurance company’s national /paybill
page looked up my IP, and discovered I’m in New York (I’m actually
near Philadelphia) and redirected me to a “sorry, we don’t do business
in your area” page. My T1 must route through New York, I guess.
Luckily Google was able to find the real payment page.

Walter

On Fri, Feb 25, 2011 at 3:38 AM, Tushar G. [email protected]
wrote:

For my upcoming application I need to find the location of the user.
I am doing this by using the “GeoIp” plugin.

As others have pointed out, this is pretty unreliable. My home-based
IP maps to a location several counties (~60 miles) away from where
I actually live.

And while on the road using a Verizon MiFi card, my location was
identified as somewhere on the East Coast, when I was actually
in a moving vehicle crossing the salt flats in the state of Utah :slight_smile:

Depending on your need for accuracy, you may also want to look into
the newer HTML5 location api as a cross-check.

http://dev.w3.org/geo/api/spec-source.html

HTH, and good luck!

Hassan S. ------------------------ [email protected]
twitter: @hassan

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs