<br>Has anyone successfully used Python on Windows with SSH connections to Cisco devices? I'm referring to using a Python module (Paramiko, pyssh though not actively developed, Twisted.conch, etc.) and not shelling out via Pexpect (doesn't work on Windows) or Plink. I need to connect to hundreds of Cisco routers/switches so that I can run numerous commands to gather data. Here is a snippet of my Telnet commands that I need working via SSH:
<br><br><div style="margin-left: 40px;">self.tn.write("wr\n")<br>(index, match, read) = self.tn.expect(["OK"], 15)<br>if not match:<br> self.tn.write("yes\n")<br>time.sleep(random.uniform(0,2))
<br>self.tn.write("copy tf runn\n")<br>self.tn.read_until("host []?", 7)<br>time.sleep(random.uniform(0,2))<br>self.tn.write("192.168.136.51\n")<br>self.tn.read_until("filename []?", 7)
<br>time.sleep(random.uniform(0,2))<br>self.tn.write(self.filename +"\n")<br>time.sleep(random.uniform(0,2))<br>self.tn.read_until("[running-config]?", 7)<br>time.sleep(random.uniform(0,2))<br>self.tn.write
("\n")<br></div><br><br>I've been able to get the following to work, but the TCP connection closes after each command:<br><br><div style="margin-left: 40px;">import paramiko<br><br>client = paramiko.SSHClient
()<br><br># ignore host keys for the test<br>client.set_missing_host_key_policy(paramiko.MissingHostKeyPolicy())<br><br>client.connect('host####', 22, 'user####', 'passw####')<br>(stdin, stdout, stderr) =
client.exec_command('sh ver | i IOS')<br>print stdout.read()<br></div><br><br>I've read that I can use a dummy channel (not sure the difference between a channel and a TCP connection) to keep the connection active. I've read the docs and I've searched the net, but I can't seem to find a good example that helps. Programming isn't my day job so I'm not that great at it. Any help would be great.
<br><br><br>Thanks!<br><br>