BASH/tor-block.sh:
Fixed dublicate IP's Made it more configuration friendly / more automatic 1st run
This commit is contained in:
parent
ae5e1d1832
commit
f247a08931
|
@ -1,33 +1,36 @@
|
||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
# Found at http://www.brianhare.com/wordpress/2011/03/02/block-tor-exit-nodes-using-bash-script/#codesyntax_1
|
# Found at http://www.brianhare.com/wordpress/2011/03/02/block-tor-exit-nodes-using-bash-script/#codesyntax_1
|
||||||
# Mods (if any) by MadMakz
|
# Mods (if any) by MadMakz
|
||||||
IPTABLES_TARGET="DROP"
|
IPTABLES_SOURCE="INPUT"
|
||||||
IPTABLES_CHAINNAME="TOR"
|
IPTABLES_TARGET="DROP"
|
||||||
|
IPTABLES_CHAINNAME="TOR"
|
||||||
WORKING_DIR="/tmp/"
|
|
||||||
|
WORKING_DIR="/tmp/"
|
||||||
# get IP address of eth0 network interface
|
|
||||||
IP_ADDRESS=$(ifconfig eth0 | awk '/inet addr/ {split ($2,A,":"); print A[2]}')
|
# get IP address of eth0 network interface
|
||||||
|
IP_ADDRESS=$(ifconfig eth0 | awk '/inet addr/ {split ($2,A,":"); print A[2]}')
|
||||||
if ! iptables -L "$IPTABLES_CHAINNAME" -n >/dev/null 2>&1 ; then #If chain doesn't exist
|
|
||||||
iptables -N "$IPTABLES_CHAINNAME" >/dev/null 2>&1 #Create it
|
if ! iptables -L "$IPTABLES_CHAINNAME" -n >/dev/null 2>&1 ; then #If chain doesn't exist
|
||||||
fi
|
iptables -N "$IPTABLES_CHAINNAME" >/dev/null 2>&1 #Create it
|
||||||
|
iptables -A "$IPTABLES_CHAINNAME" -j RETURN >/dev/null 2>&1 #Can be deleted with: iptables -D "$IPTABLES_SOURCE" -j "$IPTABLES_CHAINNAME"
|
||||||
cd $WORKING_DIR
|
iptables -I "$IPTABLES_SOURCE" -j "$IPTABLES_CHAINNAME" >/dev/null 2>&1
|
||||||
|
fi
|
||||||
wget -q -O - "https://check.torproject.org/cgi-bin/TorBulkExitList.py?ip=$IP_ADDRESS&port=80" -U NoSuchBrowser/1.0 > temp_tor_list2
|
|
||||||
wget -q -O - "https://check.torproject.org/cgi-bin/TorBulkExitList.py?ip=$IP_ADDRESS&port=9998" -U NoSuchBrowser/1.0 >> temp_tor_list2
|
cd $WORKING_DIR
|
||||||
sed -i 's|^#.*$||g' temp_tor_list2
|
|
||||||
|
wget -q -O - "https://check.torproject.org/cgi-bin/TorBulkExitList.py?ip=$IP_ADDRESS&port=80" -U NoSuchBrowser/1.0 > temp_tor_list2
|
||||||
iptables -F "$IPTABLES_CHAINNAME"
|
wget -q -O - "https://check.torproject.org/cgi-bin/TorBulkExitList.py?ip=$IP_ADDRESS&port=9998" -U NoSuchBrowser/1.0 >> temp_tor_list2
|
||||||
|
sed -i 's|^#.*$||g' temp_tor_list2
|
||||||
CMD=$(cat temp_tor_list2 | uniq | sort)
|
|
||||||
|
iptables -F "$IPTABLES_CHAINNAME"
|
||||||
for IP in $CMD; do
|
|
||||||
let COUNT=COUNT+1
|
CMD=$(cat temp_tor_list2 | sort | uniq)
|
||||||
iptables -A "$IPTABLES_CHAINNAME" -s $IP -j $IPTABLES_TARGET
|
|
||||||
done
|
for IP in $CMD; do
|
||||||
|
let COUNT=COUNT+1
|
||||||
iptables -A "$IPTABLES_CHAINNAME" -j RETURN
|
iptables -A "$IPTABLES_CHAINNAME" -s $IP -j $IPTABLES_TARGET
|
||||||
|
done
|
||||||
rm -f $WORKING_DIR/temp_tor*
|
|
||||||
|
iptables -A "$IPTABLES_CHAINNAME" -j RETURN
|
||||||
|
|
||||||
|
rm -f temp_tor*
|
Reference in New Issue