[Tutor] Python on Windows with SSH for Cisco devices
Andreas Kostyrka
andreas at kostyrka.org
Fri Jul 13 22:07:20 CEST 2007
I haven't done anything like that as I don't use Windows for anything serious. But I see basically no problem, as at least some of the packages you've mentioned are portable to marginal OSes like Windows *g*
So my tip would be, start implementing, I personally would probably stick to conch for many concurrent sessions, and come back (or use the twisted list) when you encounter troubles.
Andreas
-- Ursprüngl. Mitteil. --
Betreff: [Tutor] Python on Windows with SSH for Cisco devices
Von: "Chris Hallman" <challman at gmail.com>
Datum: 13.07.2007 19:51
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:
self.tn.write("wr\n")
(index, match, read) = self.tn.expect(["OK"], 15)
if not match:
self.tn.write("yes\n")
time.sleep(random.uniform(0,2))
self.tn.write("copy tf runn\n")
self.tn.read_until("host []?", 7)
time.sleep(random.uniform(0,2))
self.tn.write("192.168.136.51\n")
self.tn.read_until("filename []?", 7)
time.sleep(random.uniform(0,2))
self.tn.write(self.filename +"\n")
time.sleep(random.uniform(0,2))
self.tn.read_until("[running-config]?", 7)
time.sleep(random.uniform(0,2))
self.tn.write("\n")
I've been able to get the following to work, but the TCP connection closes
after each command:
import paramiko
client = paramiko.SSHClient()
# ignore host keys for the test
client.set_missing_host_key_policy(paramiko.MissingHostKeyPolicy())
client.connect('host####', 22, 'user####', 'passw####')
(stdin, stdout, stderr) = client.exec_command('sh ver | i IOS')
print stdout.read()
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.
Thanks!
_______________________________________________
Tutor maillist - Tutor at python.org
http://mail.python.org/mailman/listinfo/tutor
More information about the Tutor
mailing list