Cisco スイッチに telnet で接続し、いくつかのコマンドを実行しようとしています。ホストが存在しないかどうかを確認できますが、ユーザー名またはパスワードが正しいかどうかを確認する方法がわかりません。これは私がこれまでに得たものです(これは私のクラスの一部です)
def login(self):
if self.user_name and self.password:
try:
self.connection=telnetlib.Telnet(self.telnet_host)
try:
self.connection.read_until('sername:',1)
self.connection.write(self.user_name+'\r\n')
self.connection.read_until('assword:',1)
self.connection.write(self.password+'\r\n')
self.connection.read_until(self.prompt,1)
print "Connected"
self.loggedON=True
except EOFError:
print "Authentication to "+ self.telnet_host+" failed.\n"
return
except:
print "Can't connect to "+self.telnet_host+"\n"
return
else:
if not self.user_name:
self.user_name=raw_input("Username: ")
self.login()
else:
self.password=raw_input("Password: ")
self.login()
パスワードまたはユーザー名が間違っていても、接続されていると表示されます。