Categories
geocode-glib Gnome

Last month of OPW internship

More than 2 months have passed since I started working on GeoIP server and client libraries. The libraries are now ready to use. They provide IP address based Geolocation information.

To use the client library, all you have to do is – create a GeocodeIpclient object and perform a search for Geolocation information. The search function has both synchronous and asynchronous versions –

[code]
void geocode_ipclient_search_async (GeocodeIpclient *ipclient,
GCancellable *cancellable,
GAsyncReadyCallback callback,
gpointer user_data);

char *geocode_ipclient_search (GeocodeIpclient *ipclient,
GError **error);
[/code]

To have a better look at how to call these functions visit test-geoip.c

Since we do not have a web service yet, you have to run the GeoIP server at your localhost before you use the client to query for geolocation.

Last week, I’ve added support to update Maxmind city and country databases. Since IP addresses are reassigned, the databases need to be updated. If they are not updated, they loose about 1.5% accuracy each month.

Maxmind update their databases on first Tuesday of every month. So all you need to do is to run the updater (we call it geoip-update) from a cron job. That way you don’t have to worry about downloading the databases manually.
If you are interested to know how accurate the Geolocation data is then visit this link

If you use the Geocode GeoIP libraries now, you will see that the geolocation information based on IP is not as accurate as your google map shows in your smart phone or firefox shows if you enable location sharing from it. That’s because they use a lot of other information e.g. WiFi access point data, cell tower ids etc. to provide you a very accurate location.

The next task that I am working upon now is to increase accuracy of GeoLocation information provided by Geocode GeoIP libraries.

14 replies on “Last month of OPW internship”

How do I run the server locally? I see 2 binaries under geocode-glib/geocode-ip-server:

geoip-lookup
geoip-update

I guess its the latter? If i run it:

$ geocode-glib/geocode-ip-server/geoip-update
Updating GeoLiteCity.dat database
Could not download the database: Error opening file ‘/usr/share/GeoIP/GeoLiteCity.dat.gz’: Permission denied
Updating GeoIP.dat database
Could not download the database: Error opening file ‘/usr/share/GeoIP/GeoIP.dat.gz’: Permission denied
[zeenix@z-laptop geocode-glib]$ sudo geocode-glib/geocode-ip-server/geoip-update
[sudo] password for zeenix:
Updating GeoLiteCity.dat database
Could not download the database: Operation not supported
Updating GeoIP.dat database
Could not download the database: Operation not supported

freegeoip.net uses the same databases that we are using – GeoLite databases. You should not have any problem in downloading them. The binary geoip-update in the geocode-glib package should do the work for you. The databases that we use are free for all. Here are their URIs –
1. GeoLite Country
2. GeoLite City

One reason of not using freegeoip.net can be – they have put a limit to the number of queries per hour. If you use the geocode-glib server and client libraries, you have both the server and the client. Hence no need to wait!

The script – https://git.gnome.org/browse/geocode-glib/tree/geocode-glib/geocode-ip-server/tests/launch-web-server.sh will launch a server at your localhost:12345. The binary for the server is – geocode-glib/geocode-ip-server/geoip-lookup. Therefore you can also put this binary in your cgi-bin directory if you already have a server running at your end.

geoip-update is the database updater. The server needs a database to query for the IP addresses. We take the database from Maxmind. They regularly update their databases to maintain accuracy. Hence the need for the updater.

Maxmind limits number of downloads in a day. That might be a reason why you got “Could not download the database: Operation not supported”. Could you please try to run geoip-update as a root (since it tries to install the databases at /usr/share/GeoIP/GeoIP.dat.gz) once more and let me know if you get the same error.

Thanks for your comment! 🙂 I need to write a readme for the libraries.

Thanks for your quick replies. 🙂 I tried many times but I keep getting the same error:

$ sudo ./geoip-update
[sudo] password for zeenix:
Updating GeoLiteCity.dat database
Could not download the database: Operation not supported
Updating GeoIP.dat database
Could not download the database: Operation not supported

I was able to download GeoLiteCity.dat.gz using wget once but now I get 403 Forbidden each time I try and that means I can’t download the other file. However, GeoIP fedora package already comes with that db, GeoIP.dat so I was hoping i can already test with some accuracy.

However, when I run:

./launch-web-server.sh start
Please start debugging at http://localhost:12345/cgi-bin/geoip-lookup

The following vala code:

var ip_client = new Ipclient.for_ip (“213.243.180.91”);
//ip_client.server = “http://freegeoip.net/json/”;
try {
var location_data = ip_client.search ();
print (“%snn”, location_data);

prints me this:

{“results”:{“213.243.180.91”:[{“address”:[{“name”:”Finland”,”code”:”FI”,”type”:”country”}],”accuracy”:”country”,”attribution”:”This product includes GeoLite data created by MaxMind, available from http://www.maxmind.comn“}]},”status”:”OK”}

while if i uncomment the ip_client.server = “http://freegeoip.net/json/” above, I get this:

{“ip”:”213.243.180.91″,”country_code”:”FI”,”country_name”:”Finland”,”region_code”:”13″,”region_name”:”Southern Finland”,”city”:”Helsinki”,”zipcode”:””,”latitude”:60.1756,”longitude”:24.9342,”metro_code”:””,”areacode”:””}

For the record, the latter is a lot more accurate. 🙂

In your example, geoip-lookup is using GeoIP.dat database. That’s why the “accuracy” field in the json is showing “country” and that’s why it’s showing very little information. If you put GeoLiteCity.dat in the same directory from where the geoip-lookup is picking up the GeoIP.dat you can see more detailed information. Here’s what I get using the IP address in your example –

./test-geoip --ip 213.243.180.91
{"results":{"213.243.180.91":[{"location":{"latitude":60.17559814453125,"longitude":24.934200286865234},"address":[{"name":"Helsinki","type":"city"},{"name":"Southern Finland","code":"13","type":"region"},{"name":"Finland","code":"FI","type":"country"}],"timezone":"Europe/Helsinki","accuracy":"city","attribution":"This product includes GeoLite data created by MaxMind, available from http://www.maxmind.comn"}]},"status":"OK"}

I am using GeoLiteCity.dat. Hence the information is more accurate and the “accuracy” field in the json is showing “city”. Happy now? 😀

We are trying to put more accurate information. I am working on that now.

Once again i got my answers before you could reply. 🙂

zeenix, you don’t need to find the external ip though, the server can find it for you, including if you go through proxies
hadess: if i don’t set the IP, I am told i’m in US
zeenix, you’re accessing it through localhost, aren’t you?
zeenix, the server is supposed to be running on a host across the internet
ah
like, geoip.gnome.org for example…
understood

Comments are closed.