【发布时间】:2016-04-07 06:09:13
【问题描述】:
我正在用 Python 编写脚本,我正在使用 pxssh 和 pexpect 来完成工作,问题是我无法成功发送任何命令,我相信这是由于 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)
SSH 连接成功后的 MOTD 横幅和输出:
***********************************************
* *
* 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>
【问题讨论】: