Geeking with GeoIP
July 11th, 2009 | by Sean |In the continuing theme of geography; I started playing around with MaxMind’s libGeoIP C API for integration into the Blitzed Open-Proxy Monitor (BOPM) for EsperNet (for more information on this, contact me directly).
This, like the Google Maps API, is a remarkably easy API to use. For EsperNet’s purposes, we only want to discover the country code of each user connecting to the network. It’s pretty much as simple as saying “Hey libGeoIP, what country is 1.2.3.4 from?”
#include <stdio.h>
#include <GeoIP.h>
int main(int argc, char *argv[]) {
char *addr = argv[1];
// get geoip.dat from http://www.maxmind.com/app/geolitecountry
GeoIP *gi = GeoIP_open("geoip.dat", GEOIP_MEMORY_CACHE | GEOIP_CHECK_CACHE);
printf("%s is from %s (%s)\n",
GeoIP_country_name_by_addr(gi, addr),
GeoIP_country_code_by_addr(gi, addr));
GeoIP_close(gi);
}
I’m wondering what else I can integrate this into… maybe ircservices for statistics purposes.
Software Developer, Consultant, and Geek.
You must be logged in to post a comment.