<br>Here&#39;s one of my favorite programs to date (see attachment). It&#39;s a multi-threaded ISDN testing program. Here&#39;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&#39;m looking into Paramiko and Twisted, however I&#39;m not the best of programmers. I&#39;ve been able to learn enough to complete tasks such as this. Here&#39;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(&#39;rtr3926&#39;, 22, &#39;user&#39;, &#39;passw&#39;)<br>(stdin, stdout, stderr) = client.exec_command(&#39;sh ver | i IOS&#39;)<br>print stdout.read()<br>#(stdin, stdout, stderr) = client.exec_command
(&#39;sh ver | i IOS&#39;)<br>#print stdout.read()<br></div><br>The only problem is it drops the channel after the first &quot;sh ver&quot;.<br>&nbsp;<br><br><div><span class="gmail_quote">On 7/12/07, <b class="gmail_sendername">
Eli Criffield</b> &lt;<a href="mailto:elicriffield@gmail.com">elicriffield@gmail.com</a>&gt; 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&#39;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&#39;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&nbsp;&nbsp;templates and
<br>concurrent connections.<br><br><br>Eli Criffield<br><br>On 7/12/07, Chris Hallman &lt;<a href="mailto:challman@gmail.com">challman@gmail.com</a>&gt; wrote:<br>&gt;<br>&gt; Does anyone have an example of a SSHv2 client script? I need to write a
<br>&gt; script that uses SSHv2 to execute multiple commands on hundreds of routers.<br>&gt; I already have a script that does this with the Telnetlib. I need to<br>&gt; transition to SSHv2.<br>&gt;<br>&gt;<br>&gt;<br>&gt; _______________________________________________
<br>&gt; Twisted-Python mailing list<br>&gt; <a href="mailto:Twisted-Python@twistedmatrix.com">Twisted-Python@twistedmatrix.com</a><br>&gt; <a href="http://twistedmatrix.com/cgi-bin/mailman/listinfo/twisted-python">http://twistedmatrix.com/cgi-bin/mailman/listinfo/twisted-python
</a><br>&gt;<br>&gt;<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>