How to control a TPLINK router with a python script

How to control a TPLINK router with a python script
How to control a TPLINK router with a python script
2020-04-07 05:58:09 - last edited 2020-08-27 01:48:57
Model:Adapter
Hardware Version: V6
Firmware Version:

I wanted to know whether there is a tool that allows me to connect to a router and shut it down, and then reboot it from a python script.

 

I know that if I write in a python script: import os and then do os.system("ssh -l root 192.168.2.1"), I can connect through python to my router. But then, I don't know how to apply the router's password, and to log into it, in order to reboot it.

 

So after working on it a bit here is the code that I have written in order to connect to my router with an SSH session using a python script:

 

 import os, urllib, urllib2, re

    def InterfaceControl():
       #os.system("echo training")
       os.system("ssh -l root 192.168.2.1")
       os.system("echo yes")
       os.system("echo My_ROUTER_PASSWORD")
       os.system("shutdown -r")



     def main():
         InterfaceControl()


     if __name__=="__main__":
         main()

 

The problem is that I still can not connect to my router with this code, and moreover, IDLE (the editor I use to write and run python script) crashes. Can anyone help me improve this code?

1
1
#1
Options
1 Accepted Solution
Re:How to control a TPLINK router with a python script-Solution
2020-08-27 01:48:43 - last edited 2020-08-27 01:48:57

@PrettyThunder 

Good day.

Sorry for the delay.

May I know the model number of your wireless router?

You could try to use the Tether APP  or router’s web interface to manage the APP.

As for the python script, I am really sorry that we are not able to provide more details about it.

Thank you very much for your understanding and support.

Recommended Solution
0
0
#3
Options
4 Replies
Re:How to control a TPLINK router with a python script-Solution
2020-08-27 01:48:43 - last edited 2020-08-27 01:48:57

@PrettyThunder 

Good day.

Sorry for the delay.

May I know the model number of your wireless router?

You could try to use the Tether APP  or router’s web interface to manage the APP.

As for the python script, I am really sorry that we are not able to provide more details about it.

Thank you very much for your understanding and support.

Recommended Solution
0
0
#3
Options
Re:How to control a TPLINK router with a python script
2020-12-19 05:12:11 - last edited 2021-01-22 09:50:31

PrettyThunder wrote

I wanted to know whether there is a tool that allows me to connect to a router and shut it down, and then reboot it from a python script.

 

I know that if I write in a python script: import os and then do os.system("ssh -l root 192.168.2.1"), I can connect through python to my router. But then, I don't know how to apply the router's password, and to log into it, in order to reboot it.

 

So after working on it a bit here is the code that I have written in order to connect to my router with an SSH session using a python script:

 

 import os, urllib, urllib2, re

    def InterfaceControl():
       #os.system("echo training")
       os.system("ssh -l root 192.168.2.1")
       os.system("echo yes")
       os.system("echo My_ROUTER_PASSWORD")
       os.system("shutdown -r")



     def main():
         InterfaceControl()


     if __name__=="__main__":
         main()

 

The problem is that I still can not connect to my router with this code, and moreover, IDLE (the editor I use to write and run python script) crashes. Can anyone help me improve this code?

 

 

 

 

 

I relies upon your tp link model and firmware.

0
0
#4
Options
Re:How to control a TPLINK router with a python script
2021-01-27 16:11:56

@PrettyThunder never understood python, anyway thanks for posting!

0
0
#5
Options
Re:How to control a TPLINK router with a python script
a week ago

@PrettyThunder https://github.com/epsi95/TPLink-Python

0
0
#6
Options