Skip to content

Instantly share code, notes, and snippets.

Created November 8, 2015 18:52
Show Gist options
  • Save protyposis/b7b06e99410d81de688c to your computer and use it in GitHub Desktop.
Save protyposis/b7b06e99410d81de688c to your computer and use it in GitHub Desktop. IP update script for OpenWRT
# 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 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 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 website:
# server=/
# server=/
# Author: Mario Guggenberger /
# Use and share freely!
scriptdir=$(dirname "$0")
# read previously saved IP
previous_ip=$(cat $ipfile)
# get current IP
current_ip=$(wget -q -O - | grep -Eo "[0-9\.]+")
# check for IP change
if [ "$previous_ip" == "$current_ip" ]
echo "IP is still the same ($current_ip)"
echo "IP changed from $previous_ip to $current_ip"
result=$(wget -q -O -
echo $result
# check for valid response
if [ $(echo $result | grep -cim1 "activeUntil") -eq 1 ]
echo "$current_ip" > $ipfile
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment