2

Here is the code that I am using. For some reasons it is not working, what am I missing? Not sure what else I can add to my post but the site is asking me to add more details

account = Account(name= 'MiniMe', password = 'password')
conn = SSH2()
conn.debug=5

try:
    print "Attempting a connection to 1.1.1.1"
    conn.connect('1.1.1.1')
    print (conn.response)
except:
    e = sys.exc_info()[0]
    print "Error connecting to host:", e
    conn="N/A"


try:
    print "Authenticating to 1.1.1.1"
    conn.login(account)
    print (conn.response)
except:
    e = sys.exc_info()[0]
    print e

conn.execute('ls -la')
print (conn.response)

The output looks like this

Attempting a connection to  1.1.1.1.
generic: Rejecting ssh-rsa host key for 1.1.1.1: 3432432j4k32j4k32j42j34kj432
generic: Attempting to authenticate MiniMe
generic: Authenticating with _paramiko_auth_password
None
Authenticating to  1.1.1.1
generic: Attempting to app-authenticate MiniMe.
generic: waiting for: ['[\\r\\n][^\\r\\n]*(?:bad secrets|denied|invalid|too short|incorrect|connection timed out|failed|failure)', 'login as:', '(?:s\\/key|otp-md4) (\\d+) (\\S+)', 'password:? *$', '[\\r\\n](?:[^0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ\\!\\"\\#\\$\\%\\&\\\'\\(\\)\\*\\+\\,\\-\\.\\/\\:\\;\\<\\=\\>\\?\\@\\[\\\\\\]\\^\\_\\`\\{\\|\\}\\~\\ \\\t\\\n\\\r\\\x0b\\\x0c]*|[\\x1b\\x07\\x00]*)[\\[\\<]?\\w+(?:(?:(?:[\\w+\\-]+)\\@)?(?:[\\w+\\-\\.]+))?:?(?:(?:(?:(?:[\\w\\+\\-\\._]+))?(?:/(?:[\\w\\+\\-\\._]+))*/?)|~(?:(?:(?:[\\w\\+\\-\\._]+))?(?:/(?:[\\w\\+\\-\\._]+))*/?)?)?[: ]?(?:(?:(?:(?:[\\w\\+\\-\\._]+))?(?:/(?:[\\w\\+\\-\\._]+))*/?)|~(?:(?:(?:[\\w\\+\\-\\._]+))?(?:/(?:[\\w\\+\\-\\._]+))*/?)?)?(?:\\((?:[\\w\\+\\-\\._]+)\\))?[\\]\\-]?[#>%\\$\\]] ?[^0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ\\!\\"\\#\\$\\%\\&\\\'\\(\\)\\*\\+\\,\\-\\.\\/\\:\\;\\<\\=\\>\\?\\@\\[\\\\\\]\\^\\_\\`\\{\\|\\}\\~\\ \\\t\\\n\\\r\\\x0b\\\x0c]*\\Z']
generic: Expecting a prompt
generic: Expected pattern: <generator object <genexpr> at 0x000000000349C990>
aix: Protocol: driver replaced: generic -> aix
aix: Protocol.app_authenticate(): driver replaced
aix: waiting for: ['[\\r\\n][^\\r\\n]*(?:bad secrets|denied|invalid|too short|incorrect|connection timed out|failed|failure)', 'login as:', '(?:s\\/key|otp-md4) (\\d+) (\\S+)', "[\\r\\n]\\w+\\'s Password: $", '[\\r\\n](?:[^0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ\\!\\"\\#\\$\\%\\&\\\'\\(\\)\\*\\+\\,\\-\\.\\/\\:\\;\\<\\=\\>\\?\\@\\[\\\\\\]\\^\\_\\`\\{\\|\\}\\~\\ \\\t\\\n\\\r\\\x0b\\\x0c]*|[\\x1b\\x07\\x00]*)[\\[\\<]?\\w+(?:(?:(?:[\\w+\\-]+)\\@)?(?:[\\w+\\-\\.]+))?:?(?:(?:(?:(?:[\\w\\+\\-\\._]+))?(?:/(?:[\\w\\+\\-\\._]+))*/?)|~(?:(?:(?:[\\w\\+\\-\\._]+))?(?:/(?:[\\w\\+\\-\\._]+))*/?)?)?[: ]?(?:(?:(?:(?:[\\w\\+\\-\\._]+))?(?:/(?:[\\w\\+\\-\\._]+))*/?)|~(?:(?:(?:[\\w\\+\\-\\._]+))?(?:/(?:[\\w\\+\\-\\._]+))*/?)?)?(?:\\((?:[\\w\\+\\-\\._]+)\\))?[\\]\\-]?[#>%\\$\\]] ?[^0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ\\!\\"\\#\\$\\%\\&\\\'\\(\\)\\*\\+\\,\\-\\.\\/\\:\\;\\<\\=\\>\\?\\@\\[\\\\\\]\\^\\_\\`\\{\\|\\}\\~\\ \\\t\\\n\\\r\\\x0b\\\x0c]*\\Z']
aix: Expecting a prompt
aix: Expected pattern: <generator object <genexpr> at 0x000000000349C9D8>
aix: Sending 'ls -la\r'
<class 'Exscript.protocols.Exception.TimeoutException'>
aix: Expecting a prompt
aix: Expected pattern: <generator object <genexpr> at 0x000000000349CAB0>
MiniMe
  • 1,057
  • 4
  • 22
  • 47
  • Have you tried connecting via ssh to the host from the same machine you are using this script? What if you try to increase the timeout (.set_timeout(60)) – Markon Dec 04 '15 at 14:19
  • I did , it is working. This is certainly not a timeout problem, the host is responsive. For some reasons Exscript is not getting the response that it is waiting for. As you can see Exscript is changing the prompt from generic to AIX, that means it is exchanging packets with the ssh server – MiniMe Dec 04 '15 at 15:19
  • have you taken a look at this http://stackoverflow.com/questions/34042841/python-exscript-junos already? It seems that AIX is waiting for some sort of input. – Markon Dec 04 '15 at 15:33
  • Could you execute "ls -la\n"? – Markon Dec 04 '15 at 15:40
  • Nope...I need a way to find out if the first authentication took place. The second step (App authenticate should not happen...) – MiniMe Dec 04 '15 at 16:09

1 Answers1

0

Here are the key lines from the output:

Attempting a connection to  1.1.1.1.
# ... (messages from AIX)
None
# ... (messages from AIX)
Authenticating to  1.1.1.1
# ... (messages from AIX)
<class 'Exscript.protocols.Exception.TimeoutException'>
# ... (messages from AIX)

These are the printed messages from the two try/except statements. Here's the most important line:

print (conn.response)
#=> None

... happens after an attempted connection.

The connection isn't working. The connection receives a blank response, i.e. None, and then it prints it out. That also explains the TimeoutException lower down. Timeout essentially means "I asked for Internet, and received silence." (The way this program is written, it will attempt to authenticate even when the initial connection fails. Don't worry, it's easily fixed.)

Maybe the IP address is mistyped? Alternatively, try adding http:// in front of the URL.

order
  • 131
  • 7