GeoIP is the standard tool. In FreeBSD, you can find it at net/GeoIP
I've only used the programming aPI, but it looks like it comes with a few commandline utilities
Code:
[~]% grep bin /ports/net/GeoIP/pkg-plist
bin/geoiplookup
bin/geoiplookup6
bin/geoipupdate
bin/geoipupdate.sh