Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
TVUnblock.com IP update script for OpenWRT
#!/bin/sh
# TVUnblock.com IP updater
# Checks for changed WAN IP and registers it at the TVUnblock service.
#
# Run this script periodically with cron or hook it to a WAN IP changed event.
# To run this script every 10 minutes with cron:
# */10 * * * * /pathtoscript/tvunblock.sh
#
# TVUnblock asks for only one activation request per hour, and may otherwise
# sanction clients with a ban. One hour is a pretty long time window though,
# and a change of your dynamic WAN IP can in the worst case lead to a full hour
# of disabled unblocking (excluding DNS cache time, which can extend this time
# even more), until the TVUnblock service is notified of the new IP.
# To work around this issue, this script performs an intermediate WAN IP check,
# and only contacts the TVUnblock server if the IP has changed. This makes
# it possible to call this script much more frequently and minimize requests
# to the TVUnblock service.
#
# This script is written for OpenWRT 15.05, but should work on DD-WRT and other
# Linux distributions as well.
#
# To get the unblocking service to work, visit tvunblock.com and set the DNS
# servers on your router to the displays displayed addresses. If your router
# runs dnsmasq (like OpenWRT and DD-WRT do), you can also configure the
# unblocking server for selected domains only, and all other traffic continues
# using your default DNS servers.
# Here's an example to use TVUnblock for Netflix only. Add the following two
# lines to your dnsmasq config, including the DNS server IPs that you're getting
# displayed on the TVUnblock.com website:
# server=/netflix.com/First-DNS-IP
# server=/netflix.com/Second-DNS-IP
#
# Author: Mario Guggenberger / protyposis.net
# Use and share freely!
scriptdir=$(dirname "$0")
ipfile="${scriptdir}/tvunblock.ip"
# read previously saved IP
previous_ip=$(cat $ipfile)
# get current IP
current_ip=$(wget -q -O - checkip.dyndns.com | grep -Eo "[0-9\.]+")
# check for IP change
if [ "$previous_ip" == "$current_ip" ]
then
echo "IP is still the same ($current_ip)"
else
echo "IP changed from $previous_ip to $current_ip"
result=$(wget -q -O - http://activate.tvunblock.com/)
echo $result
# check for valid response
if [ $(echo $result | grep -cim1 "activeUntil") -eq 1 ]
then
echo "$current_ip" > $ipfile
fi
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.