This script can be used to get the list of a list of possible Tor nodes that might contact one of your servers. This is basically a list of tor exit nodes which contacted that ip address :
But for your use case this is there :
This is a very raw python snippet that should work for you:
YOUR_SERVER_IP = '22.214.171.124'
YOUR_SERVER_PORT = '80'
USER_IP = '126.96.36.199'
data = requests.get('https://check.torproject.org/cgi-bin/TorBulkExitList.py?ip=' + YOUR_SERVER_IP + '&port='+ YOUR_SERVER_PORT)
if(data.status_code == 200):
responsedata = str(data.text)
ip_lists = responsedata.split('\n')[3:]#1st three lines are comments
if(USER_IP in ip_lists):
print("Tor usage detected")
print("Unable to connect . Error code :" + str(r.status_code))
Ideally you should save the data on disk and then query it because:
- This list is updated only after 16hr.
- You cannot query more than 4-5 times in 1hr. (Not really sure about the exact number of times and duration)