It's not possible to do one that is reliable. Some people theorize that there is a pattern to IP adresses. For example, the first octet always represent some type of country code. But the truth of the matter is that an IP can belong to any ISP, and they often have several IP ranges internationally. That's why even ISPs have to register their domain to a registration database like Internic, who then propogates their data to the dsn databases on networks worldwide. Often, this propagation process can take 72 hours before all the dsn databases are updated.
The only option then is to telnet to something like whois.arin.net, send a request for the ip, and parse the data that it returns. They're entire purpose is to keep this information up to date in the region that hey cover, a tedious process that anyone else doesn't want to spend even a modicum of time on. However many of these databases frown down on someone sticking calls to their database in a website. It's one thing to do a FINGER command every so often that only a network or web admin might use. It's something else entirely for every "Tom, Dick, and Harry" to access it whenever a page on a website refreshes.
You want to know how difficult it is to do what you are asking? Visit the abuse newsgroups and look at the hoops the pros have to go through to trace an IP address.
I hope this helps. 
Edited by Coco Brown