Block Tor IP Addresses
UPDATE: This is not efficient method. Use new method available at Block Tor IP Addresses with CSF Firewall
Here is a PHP script that you can run as cronjob every 1 hour to block Tor traffic on your server.
This require csf firewall installed on your server.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
<?php # Tor IP Blocker # https://serverok.in/block-tor-ip # Use following cronjob to run scrpt every 1 hour # 5 * * * * /usr/local/bin/php /usr/serverok/block-tor.php > /var/log/tor-block.log 2>&1 $torIPSource = "https://www.dan.me.uk/torlist/"; $torIPs = file_get_contents($torIPSource); $torIPArray = explode("\n", $torIPs); foreach ($torIPArray as $torIP) { $torIP = trim($torIP); if (empty($torIP)) { continue; } if (isValidIPv4($torIP)) { $blockCmd = "/usr/sbin/csf -d $torIP"; echo $blockCmd . "\n"; exec($blockCmd); } } function isValidIPv4($ip) { if (filter_var($ip, FILTER_VALIDATE_IP)) { return true; } else { return false; } } |
Set cronjon,
1 |
crontab -e |
Add
1 |
5 * * * * /usr/local/bin/php /usr/serverok/block-tor.php > /var/log/tor-block.log 2>&1 |