pexpect
脚本
def shujushouji():
ssh_command='ssh -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null powerd@192.168.110.254'
connection=pexpect.spawn(ssh_command)
connection.delaybeforesend=0.1
if connection.expect(r'.*password:')==0:
connection.sendline('this is password')
if connection.expect(r'HanJiang-AG1#')==0:
connection.sendline('terminal length 0')
if connection.expect(r'.*#')==0:
connection.sendline(r'show mac address-table | inc d4c1.c88e.4005 ')
if connection.expect(r'.*#')==0:
peizhi = (connection.after).decode()
#peizhi = (connection.before+connection.after).decode()
#peizhi = (aa.before+aa.after)
connection.sendline('exit')