Python Script to Reboot TP-Link Cable Modem



Wed Dec 19 21:47:42 PST 2018

TP-Link makes decent, inexpensive cable modems. We have been using one for a few months now. Here’s a python script I put together to reboot my TC-7610. You can use or extend this further to programmatically reboot your cable modem if Internet connection is out.

You may be able to use this script to reboot other models from the same manufacturer.

We use Python’s famous requests library, and leverage the Sessions object to login first and then submit the reboot form. Make sure your environment has the requests module installed.

reboot_tc7610.py

#!/usr/bin/python3

#------------------------------------------------------#
# Author: Evuraan Gmail dot com                        #
# Scope : Reboot tp-link TC-7610 cable modem           #
# ---------------------------------------------------- # 
# Freely given, no warranty, use at your own risk etc. # 
# ---------------------------------------------------- # 

import requests,sys
payload = {"loginUsername":"admin", "loginPassword":"admin"}
url = "http://192.168.100.1/goform/login"
_timeout = (10,4)
rebooturl = "http://192.168.100.1/goform/top"
headers = {'user-agent': '', "Referer": 'http://192.168.100.1/index.htm',}
	
if __name__ == "__main__":
	try:
		with requests.Session() as s:
			r = s.post(url, data=payload, headers=headers, timeout=_timeout)
			reboot = s.post(rebooturl,headers=headers, timeout=_timeout, data = {'TopReboot':'1'})
			print("Rebooted.")
	except:
		print('Failed to reboot, please intervene.')
		sys.exit(1)

	
	

Downloading:

reboot_tc7610.py can be downloaded as:

$ wget https://evuraan.info/evuraan/stuff/reboot_tc7610.py.txt --no-check-certificate -O reboot_tc7610.py 

Usage:

$ ./reboot_tc7610.py 
Rebooted.
$ ./reboot_tc7610.py 
Failed to reboot, please intervene.

Feedback

Your feedback, suggestions etc are welcome. Please leave your comments/feedback here.

License

Software License:

Copyright (c) 2018, evuraan All rights reserved.

Freely given for redistribution, or any type of use. Please be kind and pay it forward to someone else. :)

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.