TP-Link TL-R470T+ WAN Refresh Script

This is part 3 of 3… See the first post here.

In the first post of this series, I posted a script to login to the router’s web management page. The second post detailed the script that checks the status of each WAN connection.  The script below will refresh the WAN connections as needed.

This script depends on the second script “”, they should be placed in the same directory. This is the script to call to initiate a full check/refresh cycle.

At a prompt or via cron, you run this script:

$ ./ sources which sources

This script assumes two WAN connections. If you have more or less, you’ll have to make the appropriate changes. We use Google’s public DNS servers for the ping tests. This script alternates between the two, which is essential for this to work.

TP-Link TL-R470T+ WAN Status Script

This is part 2 of 3… See the first post here.

In the first post of this series, I posted a script to login to the router’s web management page. This post checks the status of each WAN connection.

This script depends on the first script “”, they should be placed in the same directory. This script assumes two WAN connections. If you have more or less, you’ll have to make the appropriate changes.

The script depends on some ugly RegEx matching to find the status of each WAN connection… I’m making due with what I have! No better interfaces are provided by TP-Link.

This is part 2 of 3… See the next post here.

Compare Symlink and Target Modified Dates (script)

Here’s a short script that will check a specific directory for symbolic links and then:

  1. check the modification date of symlinks’ respective targets
  2. if the modification date of a symlink is older than the modification date of it’s target, the symlink is “touched” updating it’s modification date

That’s it. I created this to help make a file syncing service operate slightly differently than designed. Default behavior for this sync service was to follow symlinks, uploading the target (which is the desired behavior.) However it would only monitor the symlink for modification changes, not the target. This script bridges that gap. It also gives the added benefit of controlling how often syncs may occur, as you can set cron (or whatever) to run this script at an interval of your choosing.

This script works on Mac OS X 10.8 and has only been tested on such. It should work on other versions of OSX and is likely to work on various linux flavors (though I have noticed flags and behavior for the command “stat” differ between OS X and linux.)

Modify the above directory path, escaping any spaces, and leave the asterisk (*) on the end.

TP-Link TL-R470T+ Automated Login Script

TP-LINK TL-R470T+The TP-Link TL-R470T+ Load Balance Broadband Router performs mostly as desired and advertised. This is one of the very few load balancing routers under $150, coming in at about $55. As you might expect at that price point, it’s not perfect. One major limiting factor for my application is the limit of 16 (16?!) load balance policy rules. The only major flaw I’ve encountered in my use of this hardware is it’s “Online Detection” service.

The Problem: Online Detection
Determining if each WAN connection is online is an important feature of the router. Without this there would be no reliability. My connections are not the most reliable, hence the need for this router and two ISPs. I was often getting false positives and false negatives in online detection. Both false negatives and false positives are fairly disastrous for my network. I noticed that keeping the servers set to “manual” I would only receive false negatives (connection DOWN.) When I manually updated the settings for Online Detection, I could force the router to correctly refresh the status as long as the server addresses changed. I started using Google’s Public DNS hosts for ping and name resolution (in Online Detection settings) as I couldn’t trust the “Auto” setting. This was partially due to one WAN connection being a private subnet (double NAT).

Online Detection settings page

The Solution: Automatically Update the Settings Every 5 Minutes
It’s crazy I know, but it’s been working for many months now. Requests for help from tech support and community forums received no serious answers. I crafted a couple Bash shell scripts on a local Linux (Ubuntu) machine to run every 5 minutes, automating the change in settings for Online Detection’s servers. This way a WAN connection is incorrectly marked online or offline for no longer than 5 minutes. The single disadvantage I’ve experienced from this method is normal access of the admin web page. The router only allows access to the admin pages from one IP at a time. This means you have to load and make changes between those automated accesses every 5 minutes. The interval can be changed at your discretion of course.

The script below is one part of this solution, it authenticates with the router’s web interface. The following scripts use the cookie generated by this script to access the Online Detection page. I kept the scripts separate for functionality.


This is part 1 of 3… See the next post here.