Pexpect does is not synchronized with firewall prompt

115 Views Asked by At

I am trying to get data from a firewall using Pexpect module (More specifically, pxssh). The login process is okey and the problem comes exactly in the i assignment line:

if i==2: # password or passphrase
            self.sendline(password)
            # Up to here, everything is okay#
            i = self.expect(["(?i)are you sure you want to continue connecting", original_prompt, "(?i)(?:password)|(?:passphrase for key)", "(?i)permission denied", "(?i)terminal type", TIMEOUT])

This is the firewall's dialog when a user is logged in:

Password:

Last login: Mon Sep 25 06:20:50 2017 from IPXXXX

Number of failed attempts since last successful login: 0

admin@DEVICE(active)>

I think the problem is that Pexpect don't expect these two lines of Last Login and Number of failed attempts, so the code execution is stopped in the line I said before.

Shell that the firewall uses:

admin@DEVICE(active)>

Init code of my pexpect class:

def __init__(self, host, user, password):
    str = 'ssh '+user+'@'+host
    self.user = user
    self.child = pexpect.spawn ('ssh '+user+'@'+host)
    self.child.expect ('Password:.*')
    self.child.sendline (password)
    self.child.expect (user+'.*>')
    ...

)

0

There are 0 best solutions below