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 “login.sh”, 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.
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 36 37 38 |
#!/bin/bash source login.sh if [[ $? -ne 0 ]] then echo "Login Error: " $? exit fi status=$(wget --timeout=7 -qO- --load-cookies cookies.txt --save-cookies cookies.txt --keep-session-cookies "http://$ROUTER_IP/userRpm/DiagnosticOnline.htm") [[ $status =~ diaOnlineListPara\ =\ new\ Array\(([^\)]+)\) ]] status=${BASH_REMATCH[1]} [[ $status =~ \"wan1\",.\"[a-z]+\",.\"([0-9\.]*)\",.\"([0-9\.]*)\",.\"([a-z_]*)\" ]] wan1ping=${BASH_REMATCH[1]} wan1dns=${BASH_REMATCH[2]} wan1status=${BASH_REMATCH[3]} [[ $status =~ \"wan2\",.\"[a-z]+\",.\"([0-9\.]*)\",.\"([0-9\.]*)\",.\"([a-z_]*)\" ]] wan2ping=${BASH_REMATCH[1]} wan2dns=${BASH_REMATCH[2]} wan2status=${BASH_REMATCH[3]} if [[ $wan1status = "wanconn_ok" ]] then wan1status="UP" else wan1status="DOWN" fi echo "WAN 1 is $wan1status" if [[ $wan2status = "wanconn_ok" ]] then wan2status="UP" else wan2status="DOWN" fi echo "WAN 2 is $wan2status" |
This is part 2 of 3… See the next post here.