Wicked-fast geographic targeting


I’ve long been an admirer of Maxmind, a company that provides a free database for mapping IP addresses to geographic locations. Its more than sufficient for most applications, and I use it frequently in side projects as well as my day job at companies like Heavy and Photobucket.

Yesterday I paid $15 to buy a new version of their software that maps IP addresses to company names and known “proxies” used by warez providers. We need this to start tracking click fraud at work. What surprised me most was the release of an Apache 2.0 plugin using apxs, where the geographic lookups are now handled in C vs. a higher level scripting language. The performance improvement is dramatic. Further, it makes lookups dirt simple. The plugin stores the geographic IP, city, state, company and more in environment variables and internal Apache tables. It took me about 30 minutes to set everything up, including a compile and install on a CentOS box running on Amazon’s EC2.

The end result is a set of C libraries in /usr/local/lib and data files in /usr/local/shared that can be easily integrated to your C application:

  1.  
  2. #include <GeoIP.h>
  3. int main (int argc, char *argv[]) {
  4.   GeoIP * gi;
  5.   gi = GeoIP_new(GEOIP_STANDARD);
  6.   printf("code %s\n",
  7.     GeoIP_country_code_by_name(gi, "yahoo.com"));
  8. }
  9.  

 
 
 

Leave a Reply