Python ingest of text file with IP's to do LAN network management
<p>I am trying to manage several cisco switches in a network I control.  I simply want to use pexpect to log-into each one to check uptime, just to keep an eye each morning that the devices have not rebooted.</p>

<p>I have the pexpect portion working, but I want to list all the IP's of the devices in a text file, and then using the python script, have it ingest these ip's, and one by one, log into the device and do a show version command.  Perhaps, if I define the pexpect commands as a module this would work, but not sure how to do that.  I am new to python and tried to find the answer, but after many google searches, came up empty so wanted to try here.</p>

<p>Below is my attempt in automating this, but it does not work. </p>

<p>Here is what I have thus far.  </p>

<pre><code>import pexexpect
list=raw_input('Type in name of text file:' )
fo=file(list, 'r')
tt=fo.readlines()
fo.close()

for ip in tt:
    load(ip) 

child=pexpect.spawn("telnet ip") 
child.expect("password:*")
child.sendline("mypassword")
</code></pre>
