Geo Location extracted from visitors ip address

  • Thread starter Îίκος Gr33k
  • Start date
Î

Îίκος Gr33k

Is there a way to extract out of some environmental variable the Geo
location of the user being the city the user visits out website from?

Perhaps by utilizing his originated ip address?
 
J

Jerry Hill

Is there a way to extract out of some environmental variable the Geo
location of the user being the city the user visits out website from?

Perhaps by utilizing his originated ip address?

No, you'd need to take the originating IP address and look it up in a
geolocation database or submit it to a geolocation service and get the
response back from them. It's not stored in any environment
variables.
 
S

Support by Îίκος

Στις 5/7/2013 10:28 μμ, ο/η Jerry Hill έγÏαψε:
No, you'd need to take the originating IP address and look it up in a
geolocation database or submit it to a geolocation service and get the
response back from them. It's not stored in any environment
variables.
I see but i dont know how to do this Geo location lookups.
Can you give me more specific details please?
 
T

Tim Chase

Is there a way to extract out of some environmental variable the
Geo location of the user being the city the user visits out website
from?

Perhaps by utilizing his originated ip address?

Yep. You can get an 11MB database (17MB uncompressed)

http://dev.maxmind.com/geoip/legacy/downloadable/

which you can use to either populate an existing database with
the .CSV data there, or use the binary data blob in concert with the
Python API

https://github.com/maxmind/geoip-api-python # Python + C
http://pypi.python.org/pypi/pygeoip/ # pure Python

Just be sure to adhere to the licensing terms.

-tkc
 
S

Support by Îίκος

Στις 5/7/2013 10:58 μμ, ο/η Tim Chase έγÏαψε:
Yep. You can get an 11MB database (17MB uncompressed)

http://dev.maxmind.com/geoip/legacy/downloadable/

which you can use to either populate an existing database with
the .CSV data there, or use the binary data blob in concert with the
Python API

https://github.com/maxmind/geoip-api-python # Python + C
http://pypi.python.org/pypi/pygeoip/ # pure Python

Just be sure to adhere to the licensing terms.

-tkc
Thank you ill take a look on

http://pypi.python.org/pypi/pygeoip/ # pure Python

i hope it will be easy!
 
D

Dave Angel

It is possible to look up the geographic region associated with a block of
IP addresses. That does not necessarily bear any resemblence to the actual
location of the user. It tells you the location of the Internet provider
that registered the IP addresses.

To be more specific, the last time I checked, my IP address is
registered to a location over 1000 miles away. And it's not a dedicated
IP address, so it could very well be used tomorrow by someone 200 nmiles
the other side of the registered location.

Further, I sometimes use other ISP's with different addresses, even when
I don't leave the house. And once I leave, anything's possible.

The only things that travel with me and my machine are the cookies. So
if someone has asked me my location, and if I told the truth, then that
information could remain available till I flush my cookies or change
Virtual Machines or even browsers.
 
T

Tim Chase

Στις 5/7/2013 10:58 μμ, ο/η Tim Chase έγÏαψε:
Thank you ill take a look

Alternatively, you[1] can use JavaScript in your code and have it
submit AJAX requests. This interacts with the browser, asking it
where (geographically) it thinks it is. This interacts with a GPS
some browsers (particularly mobile), while on others, it trusts the
user to report where they are. Note that at any time, the user can
decline to answer or blatantly lie[2].

-tkc


[1]
generic "you"...this requires a fair bit of coding skill and the
ability to read/understand documentation that I can't say I've seen
demonstrated in certain recent threads.

[2]
https://addons.mozilla.org/en-us/firefox/addon/geolocater/
 
G

Grant Edwards

Is there a way to extract out of some environmental variable the Geo
location of the user being the city the user visits out website from?
No.

Perhaps by utilizing his originated ip address?

There is a very poor correlation between IP address and geographical
location. I know that users of the ISPs in hometown are consistently
mis-identified as being from towns 1500km away.
 
Î

Îίκος Gr33k

Στις 5/7/2013 10:58 μμ, ο/η Tim Chase έγÏαψε:
Yep. You can get an 11MB database (17MB uncompressed)

http://dev.maxmind.com/geoip/legacy/downloadable/

Thank you very much Tim.
i am know tryitn to use it as:

import pygeoip

try:
gic = pygeoip.GeoIP('/root/GeoIPCity.dat')
host = gic.time_zone_by_addr( os.environ['HTTP_CF_CONNECTING_IP'] )
except Exception as e:
host = repr(e)

lets hope it will work!
 
Î

Îίκος Gr33k

Στις 6/7/2013 2:55 πμ, ο/η Îίκος Gr33k έγÏαψε:
Στις 5/7/2013 10:58 μμ, ο/η Tim Chase έγÏαψε:
Yep. You can get an 11MB database (17MB uncompressed)

http://dev.maxmind.com/geoip/legacy/downloadable/

Thank you very much Tim.
i am know trying to use it as:

import pygeoip

try:
gic = pygeoip.GeoIP('/root/GeoIPCity.dat')
host = gic.time_zone_by_addr( os.environ['HTTP_CF_CONNECTING_IP'] )
except Exception as e:
host = repr(e)

lets hope it will work!

Just my luck again,

PermissionError(13, 'ΆÏνηση Ï€Ïόσβασης')

ΆÏνηση Ï€Ïόσβασης = Access Denied

Why would that happen?
 
Î

Îίκος Gr33k

Στις 6/7/2013 2:58 πμ, ο/η Îίκος Gr33k έγÏαψε:
Στις 6/7/2013 2:55 πμ, ο/η Îίκος Gr33k έγÏαψε:
Στις 5/7/2013 10:58 μμ, ο/η Tim Chase έγÏαψε:
On 2013-07-05 22:08, Îίκος Gr33k wrote:
Is there a way to extract out of some environmental variable the
Geo location of the user being the city the user visits out website
from?

Perhaps by utilizing his originated ip address?

Yep. You can get an 11MB database (17MB uncompressed)

http://dev.maxmind.com/geoip/legacy/downloadable/

Thank you very much Tim.
i am know trying to use it as:

import pygeoip

try:
gic = pygeoip.GeoIP('/root/GeoIPCity.dat')
host = gic.time_zone_by_addr( os.environ['HTTP_CF_CONNECTING_IP'] )
except Exception as e:
host = repr(e)

lets hope it will work!

Just my luck again,

PermissionError(13, 'ΆÏνηση Ï€Ïόσβασης')

ΆÏνηση Ï€Ïόσβασης = Access Denied

Why would that happen?

root@nikos [~]# ls -l GeoLiteCity.dat
-rw-r--r-- 1 root root 17633968 Jul 3 02:11 GeoLiteCity.dat
root@nikos [~]# chmod +x GeoLiteCity.dat
root@nikos [~]# ls -l GeoLiteCity.dat
-rwxr-xr-x 1 root root 17633968 Jul 3 02:11 GeoLiteCity.dat*
root@nikos [~]# python
Python 3.3.2 (default, Jun 3 2013, 16:18:05)
[GCC 4.4.7 20120313 (Red Hat 4.4.7-3)] on linux
Type "help", "copyright", "credits" or "license" for more information.Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File
"/usr/local/lib/python3.3/site-packages/pygeoip-0.2.6-py3.3.egg/pygeoip/__init__.py",
line 110, in __init__
self._filehandle = codecs.open(filename, 'rb', ENCODING)
File "/usr/local/lib/python3.3/codecs.py", line 884, in open
file = builtins.open(filename, mode, buffering)
FileNotFoundError: [Errno 2] No such file or directory:
'/root/GeoIPCity.dat'
 
J

Joel Goldstick

Στις 6/7/2013 2:58 πμ, ο/η Îίκος Gr33k έγÏαψε:

Στις 6/7/2013 2:55 πμ, ο/η Îίκος Gr33k έγÏαψε:
Στις 5/7/2013 10:58 μμ, ο/η TimChase έγÏαψε:

On 2013-07-05 22:08, Îίκος Gr33k wrote:

Is there a way to extract out of some environmental variable the
Geo location of the user being the city the user visits out website
from?

Perhaps by utilizing his originated ip address?


Yep. You can get an 11MB database (17MB uncompressed)

http://dev.maxmind.com/geoip/**legacy/downloadable/<http://dev.maxmind..com/geoip/legacy/downloadable/>


http://pypi.python.org/pypi/**pygeoip/<http://pypi.python.org/pypi/pygeoip/> # pure Python


Thank you very much Tim.
i am know trying to use it as:

import pygeoip

try:
gic = pygeoip.GeoIP('/root/**GeoIPCity.dat')
host = gic.time_zone_by_addr( os.environ['HTTP_CF_**CONNECTING_IP'] )
except Exception as e:
host = repr(e)

lets hope it will work!

Just my luck again,

PermissionError(13, 'ΆÏνηση Ï€Ïόσβασης')

ΆÏνηση Ï€Ïόσβασης = Access Denied

Why would that happen?

root@nikos [~]# ls -l GeoLiteCity.dat
-rw-r--r-- 1 root root 17633968 Jul 3 02:11 GeoLiteCity.dat
root@nikos [~]# chmod +x GeoLiteCity.dat
root@nikos [~]# ls -l GeoLiteCity.dat
-rwxr-xr-x 1 root root 17633968 Jul 3 02:11 GeoLiteCity.dat*
root@nikos [~]# python
Python 3.3.2 (default, Jun 3 2013, 16:18:05)
[GCC 4.4.7 20120313 (Red Hat 4.4.7-3)] on linux
Type "help", "copyright", "credits" or "license" for more information.Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/local/lib/python3.3/**site-packages/pygeoip-0.2.6-**
py3.3.egg/pygeoip/__init__.py"**, line 110, in __init__
self._filehandle = codecs.open(filename, 'rb', ENCODING)
File "/usr/local/lib/python3.3/**codecs.py", line 884, in open
file = builtins.open(filename, mode, buffering)

Your code is not finding /root/GeoIPCity.dat because your directory has
this file: GeoLiteCity.dat
FileNotFoundError: [Errno 2] No such file or directory:
'/root/GeoIPCity.dat'


Aside from that you might have some permission problems since the file is
owned by root. You should go back to old threads where this issue was
explained.

As was also pointed out, you only get information about where your isp is
located. Phones and tablets find location from triangulating cell towers.
I don't think that laptops have that capability, and desktops probably even
less likely.

What is the purpose that you wish to serve. I don't think you've thought
this through.
 
C

Chris Angelico

To be more specific, the last time I checked, my IP address is registered to
a location over 1000 miles away. And it's not a dedicated IP address, so it
could very well be used tomorrow by someone 200 nmiles the other side of the
registered location.

Further, I sometimes use other ISP's with different addresses, even when I
don't leave the house. And once I leave, anything's possible.

That said, though, geolocation is usually accurate enough to report
which country you're in. For basic statistical analysis, that's
generally sufficient.

ChrisA
 
Î

Îίκος Gr33k

Στις 6/7/2013 3:56 πμ, ο/η Joel Goldstick έγÏαψε:
Your code is not finding /root/GeoIPCity.dat because your directory has
this file: GeoLiteCity.dat

FileNotFoundError: [Errno 2] No such file or directory:
'/root/GeoIPCity.dat'

My mistake.
Is there a differnce between GeoLiteCity.dat and GeoIPCity.dat
Aside from that you might have some permission problems since the file
is owned by root.

But he cgi scripts when running have full access to the server.
No? or they only have the kind of access that their user has also?


As was also pointed out, you only get information about where your isp
is located.
Its the best i can get to, since there is no other way to match the
users city.

Î’ Phones and tablets find location from triangulating cell
towers.Î’ I don't think that laptops have that capability, and desktops
probably even less likely.

What do you mean by that?
What is the purpose that you wish to serve.Î’ I don't think you've
thought this through.

I just dont want to store visitor's ip addresses any more, i prefer to
store its city of origin.
 
J

Joel Goldstick

Στις 6/7/2013 3:56 πμ, ο/η Joel Goldstick έγÏαψε:
Your code is not finding /root/GeoIPCity.dat because your directory has
this file: GeoLiteCity.dat

FileNotFoundError: [Errno 2] No such file or directory:
'/root/GeoIPCity.dat'

My mistake.
Is there a differnce between GeoLiteCity.dat and GeoIPCity.dat


Aside from that you might have some permission problems since the file
is owned by root.

But he cgi scripts when running have full access to the server.
No? or they only have the kind of access that their user has also?




As was also pointed out, you only get information about where your isp
is located.
Its the best i can get to, since there is no other way to match the users
city.

Î’ Phones and tablets find location from triangulating cell
towers.Î’ I don't think that laptops have that capability, and desktops
probably even less likely.

What do you mean by that?




What is the purpose that you wish to serve.Î’ I don't think you've
thought this through.

I just dont want to store visitor's ip addresses any more, i prefer to
store its city of origin.

Except its the ISP city that you are getting, not the user's
 
Î

Îίκος Gr33k

Yes i know iam only storing the ISP's city instead of visitor's homeland
but this is the closest i can get:

try:
gi = pygeoip.GeoIP('/home/nikos/GeoLiteCity.dat')
city = gi.time_zone_by_addr( os.environ['HTTP_CF_CONNECTING_IP'] )
host = socket.gethostbyaddr( os.environ['HTTP_CF_CONNECTING_IP'] )
except Exception as e:
host = repr(e)


Tried it myself and it falsey said that i'am from Europe/Athens (capital
of Greece) while i'am from Europe/Thessaloniki (sub-capital of Greece)

If we can pin-point the uvisitor more accurately plz let me know.
 
D

Dennis Lee Bieber

But he cgi scripts when running have full access to the server.
No? or they only have the kind of access that their user has also?
In any decent system, the web server runs as a particular user, and
only has access to the web content and scripts. And those scripts run as
the web server process (at most -- it may be that they run at an even more
restricted mode).

So NO, they do NOT have access to stuff under /root; for ancient
CGI-BIN style, they may be restricted to only the files in the CGI-BIN
directory.
 
Î

Îίκος Gr33k

Στις 6/7/2013 5:52 πμ, ο/η Dennis Lee Bieber έγÏαψε:
In any decent system, the web server runs as a particular user, and
only has access to the web content and scripts. And those scripts run as
the web server process (at most -- it may be that they run at an even more
restricted mode).

So NO, they do NOT have access to stuff under /root; for ancient
CGI-BIN style, they may be restricted to only the files in the CGI-BIN
directory.
Thats why i was getting permission denied vene when i had +x
when i moved the geo.dat file to /home/nikos/geo.dat then the cgi python
script was able to opened it.

It was some guy form hostgator.com that had told me that a python script
has the same level of access to anything on the filesystem as its
coressponding user running it, implying that if i run it under user
'root' the python script could access anything.

Are you sure that python scripts run under Apache user or Nobody user in
my case and not as user 'nikos' ?

Is there some way to test that?
 
Î

Îίκος Gr33k

Στις 6/7/2013 4:41 πμ, ο/η Îίκος Gr33k έγÏαψε:
Yes i know iam only storing the ISP's city instead of visitor's homeland
but this is the closest i can get:

try:
gi = pygeoip.GeoIP('/home/nikos/GeoLiteCity.dat')
city = gi.time_zone_by_addr( os.environ['HTTP_CF_CONNECTING_IP'] )
host = socket.gethostbyaddr( os.environ['HTTP_CF_CONNECTING_IP'] )
except Exception as e:
host = repr(e)


Tried it myself and it falsey said that i'am from Europe/Athens (capital
of Greece) while i'am from Europe/Thessaloniki (sub-capital of Greece)

If we can pin-point the uvisitor more accurately plz let me know.

Good morning from Greece,

All my Greece visitors as Dave correctly said have the ISP address which
here in Greece is Europe/Athens, so i have now way to distinct the
cities of the visitors.

Is there any way to pinpoint the visitor's exact location?
 
Î

Îίκος Gr33k

Στις 6/7/2013 11:30 πμ, ο/η Chris Angelico έγÏαψε:
Yes. You ask them to fill in a shipping address. They may still lie,
or they may choose to not answer, but that's the best you're going to
achieve without getting a wizard to cast Scrying.

No, no registration requirements.

you know when i go to maps.google.com its always find my exact city of
location and not just say Europe/Athens.

and twitter and facebook too both of them pinpoint my _exact_ location.

How are they able to do it? We need the same way.
 

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,994
Messages
2,570,223
Members
46,810
Latest member
Kassie0918

Latest Threads

Top