[Twisted-Python] SSHv2 client script for Cisco routers

Chris Hallman challman at gmail.com
Thu Jul 12 16:39:09 EDT 2007


Here's one of my favorite programs to date (see attachment). It's a
multi-threaded ISDN testing program. Here's the workflow:

1. Connect to each head-end router and extract all the usernames for
testing.
2. Spawn up to N threads and telnet to each device.
3. Check for a layer-1 connection.
4. Check for an existing DBU connection.
5. Extract all interfaces for testing.
6. Execute a DBU test for each interface verifying a connection takes place
and an EIGRP peer establishes.

(It does some other things specific for our network.) It writes output to a
local log file and SNMP traps on failure and program completion. I really
need to get it working using SSH. I'm looking into Paramiko and Twisted,
however I'm not the best of programmers. I've been able to learn enough to
complete tasks such as this. Here's a simple program using Paramiko:

import paramiko
import time

client = paramiko.SSHClient()

# ignore host keys for the test
client.set_missing_host_key_policy(paramiko.MissingHostKeyPolicy())

client.connect('rtr3926', 22, 'user', 'passw')
(stdin, stdout, stderr) = client.exec_command('sh ver | i IOS')
print stdout.read()
#(stdin, stdout, stderr) = client.exec_command('sh ver | i IOS')
#print stdout.read()

The only problem is it drops the channel after the first "sh ver".


On 7/12/07, Eli Criffield <elicriffield at gmail.com> wrote:
>
> Thats exactly what I've been working on, a script to automate
> connections to cisco switches, where you have to execute multiple
> commands per connection (config t, then some commands ect...)
>
> I emailed this list yesterday asking if anyone has some examples of
> how to do that and no reply yet.
>
> I'd like to get ssh worked into http://code.google.com/p/exscript/ .
> Exscript does what your doing with telnetlib and uses  templates and
> concurrent connections.
>
>
> Eli Criffield
>
> On 7/12/07, Chris Hallman <challman at gmail.com> wrote:
> >
> > Does anyone have an example of a SSHv2 client script? I need to write a
> > script that uses SSHv2 to execute multiple commands on hundreds of
> routers.
> > I already have a script that does this with the Telnetlib. I need to
> > transition to SSHv2.
> >
> >
> >
> > _______________________________________________
> > Twisted-Python mailing list
> > Twisted-Python at twistedmatrix.com
> > http://twistedmatrix.com/cgi-bin/mailman/listinfo/twisted-python
> >
> >
>
> _______________________________________________
> Twisted-Python mailing list
> Twisted-Python at twistedmatrix.com
> http://twistedmatrix.com/cgi-bin/mailman/listinfo/twisted-python
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://twistedmatrix.com/pipermail/twisted-python/attachments/20070712/f7f086a2/attachment.htm 
-------------- next part --------------
A non-text attachment was scrubbed...
Name: ISDNtest.py
Type: text/x-python
Size: 12872 bytes
Desc: not available
Url : http://twistedmatrix.com/pipermail/twisted-python/attachments/20070712/f7f086a2/attachment.py 


More information about the Twisted-Python mailing list