#!/bin/bash # # ccfind 2006-03-05, last edit 2008-08-15 # # returns ' cc:country name' for IP address input queries, # using the ip2cn-server daemon. # # Copyright (C) 2006-2008 Grant Coady GPLv2 # # 2008-08-13 # convert to ip2cn-server operation, no more access locking! :) # # check got query [ -z "$1" ] && echo " ccfind -- lookup country code and name for IP address usage $0 aa.bb.cc.dd " && exit # get server listen port port=$(gawk '/^inetport/ {print $2}' /etc/ip2cn-server.conf) # make query, may be dotquad or numeric (decimal) IP address echo "$@" | gawk -v port=$port ' BEGIN { service = "/inet/tcp/0/localhost/" port } $1 == "0" { $1 = "0." } { print |& service; service |& getline; print }' 2>/dev/null # end