This page describes a similar independent implementation - except that the dots depict where each of the website visit (aka stats, or "hits"), like this:
pnmtojpeg
, jpegtopnm
, etc
./convert.sh /path/to/geoiplite/block-database.csv /path/to/geoiplite/location.csv
ipinfo.dat
and locinfo.dat
in the current directory.
ipgeocode
, genimage.sh
and map.png
from the tarball to your webserver's
cgi-bin directory.
genimage.sh
whether the location of the data files
and the image files are correct, if not, adjust them as needed.
genimage.sh
expects to fed with IP addresses on it standard input, one per line.
It will produce a JPEG file on standard output. You will need to create a CGI script
that provides this necessary information to genimage.sh as well as returning the
output back to the webserver. This varies from webserver to another, here is one
that works with SJPPLOG (the blog software I'm using for my blog):
#!/bin/sh echo -ne "Content-Type: image/jpeg\r\n" echo -ne "Content-Disposition: inline; filename=\"stat.jpg\"\r\n" echo -ne "\r\n" awk -F"|" '{print $1}' /path/to/your/sjpplog/online.ppl.uo 2> /dev/null | sort | uniq | ./genimage.sh
In principle it is very simple.
IP Geocoding
There are many ways to do IP Geocoding. There are plenty of online geocoding services (both free and paid). I choose not to use them because I will need to do a lot of geocoding so I probably couldn't meet the terms of service from free online services, and paying for this service just to provide a stat counter is silly. Another reason is time; it is quick to use WebServices when one only needs to geocode a single IP address, but I potentially have to geocode thousands of IP address in a single request.
Thanks to maxmind.com that provides the free (as in
CC-BY-SA free) IP geocoding
database, I can do the geocoding on my own (it's just a simple look-up table).
I could use the data "as is" and perform the lookup with my favorite tools
awk
and grep
, but the voluminous data makes me wanting of a more optimised
solution.
Marking
Once I have the lat/long data, it is just a matter of plotting the markers on the map. This requires two things:
map.png
comes from http://upload.wikimedia.org/wikipedia/commons/thumb/7/74/Mercator-projection.jpg/310px-Mercator-projection.jpg
which I converted to png format as Fly only recognises png.
genimage.sh
.
genimage.sh
to use other
command-line image manipulation tools like imagemagick, graphicsmagic, gmic, etc.
awk
and grep
but the speed is much slower
(about 2 orders of magnitude slower).
Originally posted here: