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?