aboutsummaryrefslogtreecommitdiff
path: root/irssi-tor.sh
blob: 4116bfb876ade6cf89e122176c4d8f6d78b3295e (plain)
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
#!/bin/bash

SOC_PORT=4242

while `netstat -l4n | grep -qoE "^tcp(.*):${SOC_PORT}"`; do
	NEXT_PORT=$(expr ${SOC_PORT} + 1)
	echo "${SOC_PORT} isnt available, trying ${NEXT_PORT}"
	SOC_PORT=${NEXT_PORT}
done

if [ $# -ne 3 ] && [ $# -ne 0 ]; then
	echo "$0: [IRC_HOST] [IRC_PORT] [IRC_NICK]"
	exit 1
fi
IRC_HOST="$1"
IRC_PORT="$2"
IRC_NICK="$3"

sudo iptables -A INPUT -p tcp '!' -s 127.0.0.1 --dport ${SOC_PORT} -j REJECT
socat TCP4-LISTEN:${SOC_PORT},fork SOCKS4A:localhost:${IRC_HOST}:${IRC_PORT},socksport=9050 &
SOC_PID=$!
echo "socat pid ${SOC_PID}"
irssi --noconnect
echo "kill ${SOC_PID}"
kill -SIGTERM ${SOC_PID} 2>/dev/null
wait ${SOC_PID}
sudo iptables -D INPUT -p tcp '!' -s 127.0.0.1 --dport ${SOC_PORT} -j REJECT