我的 telnetlib 导入错误吗?
Are my telnetlib imports wrong?
这段代码有问题:
from telnetlib import Telnet
class doTelnet:
def login(self):
# Configure login variables for input
self.user = self.user.encode('ascii') + b'\n'
self.password = self.password.encode('ascii') + b'\n'
self.terminal_type = self.terminal_type.encode('ascii') + b'\n'
# Do login
# TODO Add functionality for user control of expected login prompt (some servers send 'Username: ', I'm sure theres other options)
self.telnet.read_until('login: ')
self.telnet.write(self.user)
self.telnet.read_until('Password: ')
try:
self.telnet.write(self.password)
print('[*]\tSuccessfully authenticated to {0}:{1}'.format(self.host, self.port))
self.login_status = 1
except Exception as self.e:
print('[!]\tError authenticating to {0}:{1}\n{2}'.format(self.host, self.port, self.e)
# Set terminal type
self.telnet.write(self.terminal_type)
它在 "self.telnet.write" 部分一直失败,我不明白为什么会这样。有人是巫师吗?
File "C:\Users\user\Downloads\CiscoIOSSNMPToolkit\doTelnet.py", line 45
self.telnet.write(self.terminal_type)
^
SyntaxError: invalid syntax
是错误。
https://github.com/GarnetSunset/CiscoIOSSNMPToolkit/blob/master/doTelnet.py
您在异常块中的 print 语句末尾缺少括号,这就是您抛出当前语法错误的原因。
这段代码有问题:
from telnetlib import Telnet
class doTelnet:
def login(self):
# Configure login variables for input
self.user = self.user.encode('ascii') + b'\n'
self.password = self.password.encode('ascii') + b'\n'
self.terminal_type = self.terminal_type.encode('ascii') + b'\n'
# Do login
# TODO Add functionality for user control of expected login prompt (some servers send 'Username: ', I'm sure theres other options)
self.telnet.read_until('login: ')
self.telnet.write(self.user)
self.telnet.read_until('Password: ')
try:
self.telnet.write(self.password)
print('[*]\tSuccessfully authenticated to {0}:{1}'.format(self.host, self.port))
self.login_status = 1
except Exception as self.e:
print('[!]\tError authenticating to {0}:{1}\n{2}'.format(self.host, self.port, self.e)
# Set terminal type
self.telnet.write(self.terminal_type)
它在 "self.telnet.write" 部分一直失败,我不明白为什么会这样。有人是巫师吗?
File "C:\Users\user\Downloads\CiscoIOSSNMPToolkit\doTelnet.py", line 45 self.telnet.write(self.terminal_type) ^ SyntaxError: invalid syntax
是错误。
https://github.com/GarnetSunset/CiscoIOSSNMPToolkit/blob/master/doTelnet.py
您在异常块中的 print 语句末尾缺少括号,这就是您抛出当前语法错误的原因。