- 转载请注明出处
需要调用的库:
import telnetlib
import datetime
import time
需要了解的telnetlib函数
telnetlib.Telnet #telnet 连接
telnetlib.read_until #等待字符出现
telnetlib.write #输入命令
telnetlib.read_very_eager #读取页面所以内容
完整代码
import telnetlib
import datetime
import time
def login_telnet(Host, username, password, finish, commands):
tn = telnetlib.Telnet(Host, port=23, timeout=20) #连接
tn.set_debuglevel(2)
tn.read_until(b'Username:') #等待Username出现
tn.write(username.encode('ascii') + b"\n") #输入username
tn.read_until(b'Password:')
tn.write(password.encode('ascii') + b"\n")
tn.read_until(b'')
file_