summaryrefslogtreecommitdiffstats
path: root/torblock.sh
blob: 5638a8016670e6b167a98e5cda3f160153913d83 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
#!/bin/bash

set -e

get_ips() {
	curl -sSL "https://check.torproject.org/cgi-bin/TorBulkExitList.py?ip=$(curl icanhazip.com)" | sed '/^#/d' | grep -Eo "([0-9]{1,3}[\.]){3}[0-9]{1,3}"
}

ipset flush tor || true
ipset create -exist tor iphash

get_ips | sed 's#^#add tor #' | ipset restore

iptables -I INPUT -m set --match-set tor src -j REJECT --reject-with icmp-admin-prohibited