title: How to control a TPLINK router with a python script
body: <p>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.</p>
  <p>I know that if I write:</p>
  <pre class="lang-py prettyprint-override"><code>import os
  os.system(&quot;ssh -l root 192.168.2.1&quot;)
  </code></pre>
  <p>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.</p>
  <p>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:</p>
  <pre><code>import os, urllib, urllib2, re
  
  def InterfaceControl():
      #os.system(&quot;echo training&quot;)
      os.system(&quot;ssh -l root 192.168.2.1&quot;)
      os.system(&quot;echo yes&quot;)
      os.system(&quot;echo My_ROUTER_PASSWORD&quot;)
      os.system(&quot;shutdown -r&quot;)
  
  
  
  def main():
      InterfaceControl()
  
  
  if __name__==&quot;__main__&quot;:
      main()
  </code></pre>
  <p>The problem is that I still can't connect to my router with this code, and moreover, IDLE (the editor I use for python scripts) crashes. Can anyone help me improve this code?</p>