나는 라우터에 액세스하기 위해 여러 점프 서버를 ssh해야하는 스크립트를 작성하려고합니다.텔넷 타임 아웃/연결 처리가 pexpect python 라우터에서 거부되었습니다
예를 들어, LocalMachine는 ---- SSH --- 서버 1 --- SSH --- 서버 2 --- 텔넷/SSH --- 라우터 그 일을하는 가장 좋은 방법이 무엇인지
확실하지, 내가 시도 pexpect를 통해 그것을 달성하십시오. 제 요구 사항은 서버 server2에서 라우터로 telnet하고 시간 초과/연결이 거부되었습니다. ssh를 시도하십시오 제안 사항을 모두 기재 해주십시오.
import time, pexpect
child = pexpect.spawn('ssh [email protected]') ##########ssh to 1st Jump server
child.expect('password: ')
child.sendline('abc')
child.expect('$')
child.sendline('ssh [email protected]') ##########ssh to 2nd Jump server
print child.before
child.expect('password:')
child.sendline('xyz')
child.expect('$')
print child.before
host=raw_input("Enter Router name: ")
try:
print "Trying Telnet ", host
child.sendline(' telnet ' + host) ### router telnet at this point i want if telnet is timeout/connection refused try ssh
print child.before
except pexpect.TIMEOUT:
print child.before
else:
child.expect(':')
child.sendline("User")
child.expect(":")
child.sendline('passwprd')
child.expect('#')
child.sendline("\n")
child.expect("#")
finally:
print "Trying SSH ", host
child.sendline(' ssh -l User ' + host)
print child.before
child.expect(":")
child.sendline('password')
child.expect('#')
child.sendline("\n")
print child.before
child.interact()
아래 사용하여 시도하지만 난 항상의 경우는 값 "$"실수는 ..what입니까? i = child.expect ([ "사용자 이름 :", "$", "계속 연결 하시겠습니까 (예/아니오)?", "password :", ">"]) –