forked from debridmediamanager/debrid-media-manager
-
Notifications
You must be signed in to change notification settings - Fork 0
/
renew-tor.sh
35 lines (29 loc) · 1.04 KB
/
renew-tor.sh
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
31
32
33
34
35
#!/bin/sh
SOCKS_PROXY="socks5h://127.0.0.1:9050"
ONION_URL="http://btdigggink2pdqzqrik3blmqemsbntpzwxottujilcdjfz56jumzfsyd.onion/search?q=Kraftfahrzeughaftpflichtversicherung"
GREP_PATTERN="Histats"
TOR_COMMAND_PORT="127.0.0.1 9051"
SLEEP_INTERVAL=30
CHECK_IP_URL="https://check.torproject.org/api/ip"
RENEW_DELAY=5
echo "Starting Tor..."
exec /usr/bin/tor -f /etc/tor/torrc &
echo "Done. Running script..."
while true; do
sleep $SLEEP_INTERVAL
PAGE_CONTENT=$(curl -x $SOCKS_PROXY -s $ONION_URL)
if [[ $? -eq 0 ]]; then
echo "$PAGE_CONTENT" | grep -qm1 $GREP_PATTERN
if [[ $? -ne 0 ]]; then
BEFORE_IP=$(curl -s --socks5 $SOCKS_PROXY $CHECK_IP_URL | jq -r '.IP')
printf 'AUTHENTICATE ""\r\nSIGNAL NEWNYM\r\n' | nc $TOR_COMMAND_PORT
sleep $RENEW_DELAY
AFTER_IP=$(curl -s --socks5 $SOCKS_PROXY $CHECK_IP_URL | jq -r '.IP')
echo "IP address renewed from $BEFORE_IP to $AFTER_IP"
else
echo "Pattern found. No need to renew IP address."
fi
else
echo "Curl command failed. Retrying..."
fi
done