0
我正在Python中編寫一個腳本,我正在使用pxssh和pexpect來完成工作,問題是我無法成功發送任何命令和我相信這是由於MOTD的旗幟。下面是我對到目前爲止的代碼再下面是旗幟的樣子:Python(pexpect和pxssh)SSH到思科ASA防火牆與MOTD橫幅
import pexpect
import getpass
import pxssh
import sys
try:
s = pxssh.pxssh()
#this is for input file/lists - host, username, and password
hostname = ('fw1.aff.tempe')
username = ('tmarciniak')
password = ('<password>')
s.login(hostname, username, password, auto_prompt_reset=False)
s.logfile = sys.stdout
#s.expect('***.*') #matching the first characters of the MOTD banner for sending command
s.sendline('enable') # run a command
s.prompt() # match the prompt
print(s.before)
#s.prompt() # match the prompt
# s.sendline('enable') # run a command
#s.prompt() # match the prompt
print(s.before) # print everything before the prompt
s.logout()
except pxssh.ExceptionPxssh as e:
print("pxssh failed on login.")
print(e)
MOTD標語和成功的SSH連接後輸出:
***********************************************
* *
* This Device is owned by Telesphere Networks *
* *
* Unauthorized Access is Strictly Prohibited *
* *
* Telesphere NOC: (800) 680-2203 *
* *
***********************************************
************************************************************************
*
* Name: Amerifirst Financial - Tempe (36714)
*
* Hostname: fw1.aff.tempe
*
* Location: 2151 E Broadway Rd
* Tempe, AZ 85282
*
* Notes:
*
************************************************************************
Type help or '?' for a list of available commands.
fw1-aff-tempe>