<br>Here's one of my favorite programs to date (see attachment). It's a multi-threaded ISDN testing program. Here's the workflow:<br><br>1. Connect to each head-end router and extract all the usernames for testing.
<br>2. Spawn up to N threads and telnet to each device.<br>3. Check for a layer-1 connection.<br>4. Check for an existing DBU connection.<br>5. Extract all interfaces for testing.<br>6. Execute a DBU test for each interface verifying a connection takes place and an EIGRP peer establishes.
<br><br>(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:
<br><br><div style="margin-left: 40px;">import paramiko<br>import time<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('rtr3926', 22, 'user', 'passw')<br>(stdin, stdout, stderr) = client.exec_command('sh ver | i IOS')<br>print stdout.read()<br>#(stdin, stdout, stderr) = client.exec_command
('sh ver | i IOS')<br>#print stdout.read()<br></div><br>The only problem is it drops the channel after the first "sh ver".<br> <br><br><div><span class="gmail_quote">On 7/12/07, <b class="gmail_sendername">
Eli Criffield</b> <<a href="mailto:elicriffield@gmail.com">elicriffield@gmail.com</a>> wrote:</span><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
Thats exactly what I've been working on, a script to automate<br>connections to cisco switches, where you have to execute multiple<br>commands per connection (config t, then some commands ect...)<br><br>I emailed this list yesterday asking if anyone has some examples of
<br>how to do that and no reply yet.<br><br>I'd like to get ssh worked into <a href="http://code.google.com/p/exscript/">http://code.google.com/p/exscript/</a> .<br>Exscript does what your doing with telnetlib and uses templates and
<br>concurrent connections.<br><br><br>Eli Criffield<br><br>On 7/12/07, Chris Hallman <<a href="mailto:challman@gmail.com">challman@gmail.com</a>> wrote:<br>><br>> Does anyone have an example of a SSHv2 client script? I need to write a
<br>> script that uses SSHv2 to execute multiple commands on hundreds of routers.<br>> I already have a script that does this with the Telnetlib. I need to<br>> transition to SSHv2.<br>><br>><br>><br>> _______________________________________________
<br>> Twisted-Python mailing list<br>> <a href="mailto:Twisted-Python@twistedmatrix.com">Twisted-Python@twistedmatrix.com</a><br>> <a href="http://twistedmatrix.com/cgi-bin/mailman/listinfo/twisted-python">http://twistedmatrix.com/cgi-bin/mailman/listinfo/twisted-python
</a><br>><br>><br><br>_______________________________________________<br>Twisted-Python mailing list<br><a href="mailto:Twisted-Python@twistedmatrix.com">Twisted-Python@twistedmatrix.com</a><br><a href="http://twistedmatrix.com/cgi-bin/mailman/listinfo/twisted-python">
http://twistedmatrix.com/cgi-bin/mailman/listinfo/twisted-python</a><br></blockquote></div><br>