How to block TOR dynamically

I’m still trying to figure out how to block users of the onion network aka TOR from using some of my sites.  I’ve found that TOR actually provides a mechanism using reverse dns lookups to help you identify tor exit nodes and take appropriate action.

Here is the TOR page that describes how to use TorDNSEL

TorDNSEL information


Another resource that may prove valuable is this fellow who put up an example php script to make use of this method to identify tor users.

TOR PHP Example

Web service to get geoip location of ip address

The problem I was trying to solve was a clean and quick way to get the country code quickly for a range of ip addresses.  There are many available libraries out there to do this but the one I found to be the easiest to use is provided via a web service which can be accessed from any scripting language to automate the process.

The only step required is a quick and free signup for an api key from this URL:

Then you can use the service like this:<your_api_key>&ip=

Which will return something like follows in your web browser:

OK;;;US;UNITED STATES;CALIFORNIA;MOUNTAIN VIEW;94043;37.3861;-122.084;-08:00