Exscript - Network Device Discovery/config gathering script (Python)
Question: I'm fairly new to python and am having difficulty with a script I am trying to
use to gather config info from cisco network devices.

After a ping test to discover which devices are up, a file is created
containing the responding IP's, and then parsed by an Exscript (python tool
for SSH/telnet access) function.

The problem is that after the ping test is complete, and the file is created
with the appropriate IP's, the script ends without beginning the quickstart or
getdevinfo functions.

Any idea why this might be?

    
    
    from Exscript.util.start import quickstart
    from Exscript.util.interact import read_login
    from Exscript.util.file import get_hosts_from_file
    from Exscript import Account
    import os
    
    account = read_login()
    hosts = open("hosts",'w')
    
    for x in range(65,85):
        if os.system("ping -c 1 -W 2 172.16.200.%s" % x) == 0:
            print 'reachable'
            hosts.write("ssh://172.16.200.%s" % x + "\n")
        else:
            print 'unreachable'
    hosts.close
    
    def getdevinfo(job,host,conn):
        print 'connection started'
        conn.execute('show ver | i Ver')
        devtypeinfo = str(conn.response)
        forparse = devtypeinfo.split()
        for word in forparse:
            if word.lower() == "security":
                file = open("hostinfo - " + str(conn.host),'w')
                print "Device Type Detected: ASA"
                conn.send("enable\r")
                conn.app_authorize(account)
                conn.execute("show run hostname")
                file.write(conn.response)
                conn.execute("show int ip bri | excl unassigned")
                file.write(conn.response)
                conn.execute("show route")
                file.write(conn.response)
                conn.send("exit\r")
                conn.close()
                file.close()
            elif word.lower() == "ios":
                file = open("hostinfo - " + str(conn.host),'w')
                print "Device Type Detected: Router"
                conn.send("enable\r")
                conn.app_authorize(account)
                conn.execute("show run | i hostname")
                file.write(conn.response)
                conn.execute("show ip int bri | excl unassigned")
                file.write(conn.response)
                conn.execute("show ip route")
                file.write(conn.response)
                conn.execute("show cdp nei")
                file.write(conn.response)
                conn.send("exit\r")
                conn.close()
                file.close()
    
    hosts2 = get_hosts_from_file('hosts')
    quickstart(hosts2, getdevinfo, max_threads = 6)
    


Answer: In case anyone runs into something similar (which I kind of doubt because this
script is so specific, maybe this wasn't the right place to post this) - the
issue was that the quickstart function was being passed an empty list of
hosts, so no connections were made.

To fix this, I skipped the get_hosts_from_file function and just added
responding hosts to a list, and passed that list to the quickstart function.

