0

4:15 PM (3 minutes ago)

Hello,

Im wondering if there is a way without using send_pexpect to validate a host. I have hundreds of IPs where i need to validate if my tacacs username is valid and if not then to expect a comment. The issue im running is that im unable to validate the expect was due to my credentials or the host is not up.

i=0 while i

    try:
            conn = SSH2(verify_fingerprint = False)
            conn.connect(allips)
            conn.login(usuario)
            adding = allips, "goods"
            print adding
            lista_buena.append(allips)
            #time.sleep(1)

    except:

            adding2 = allips,"NOT GOOD"
            print adding2
            lista_mala.append(adding2)
    i += 1

Thanks,

D' go
  • 1

2 Answers2

0

There's a great answer posted by silvado

The code referenced is very similar to what you're trying to do. They give a great example using the paramiko.SSHClient library.

https://stackoverflow.com/questions/14236346/elegant-way-to-test-ssh-availability

If that doesn't work, there's also the option to use subprocess + OpenSSH: https://gist.github.com/bortzmeyer/1284249

You may wish to adjust timers and except handling to improve performance. Serial code like this is great if you're only doing a few hundred nodes but when you get up in the 10K or higher I'd recommend using parallel-ssh.

Just my $.02 (^_^) Good luck!

janos97
  • 36
  • Alternatively you can do the following:
       try:
                conn = Telnet(logfile = logfiles, verify_fingerprint = False)
                conn.connect(allips)
                try: 
                        conn.login(usuario)
                        print "SUCCESS: " + allips
                except:
                        print "Not Priviledge: " , allips
    
    – D' go Aug 25 '16 at 08:46
0

Alternatively you can use:

    try:
            conn = Telnet(logfile = logfiles, verify_fingerprint = False)
            conn.connect(allips)
            try: 
                    conn.login(usuario)
                    print "SUCCESS: " + allips
                    filename.write('SUCCESS  ' + allips)
                    filename.write("\n")
                    filename.write("************ \n")
                    time.sleep(2)
            except:
                    print "Not Priviledge: " , allips
                    filename.write('Not Priviledge  ' + allips)
                    filename.write(" \n")
                    filename.write("************ \n")
    except:
            #print allips + "NO HOST"
            print "Not Enabled: ", allips
            filename.write('Not Priviledge  ' + allips)
            filename.write(" \n")
            filename.write("************ \n")
            filename.close()
            time.sleep(2)
D' go
  • 1