telnet-连接windows测试
目录
telnet 连接windows测试
"""
命令:
telnet 127.0.0.1
输入用户名
输入密码
"""
import telnetlib
import time
def login_windows(ip, user, password, commands):
try:
tn = telnetlib.Telnet(ip)
tn.set_debuglevel(2) # 输入输出调试信息
tn.write(b'\r\n') # 回车
rt = tn.read_until(b'login:', 5)
tn.write((user + '\r\n').encode('utf-8')) # 输入用户名后回车
rt = tn.read_until(b'password:', 5)
tn.write((password + '\r\n').encode('utf-8')) # 输入密码后回车
rt = tn.read_until(b'>', 5)
for command in commands:
tn.write((command + '\r\n').encode('utf-8'))
rt = tn.read_until(b'>', 5)
return True
except Exception as e:
print(e)
return False
if __name__ == '__main__':
ip = '127.0.0.1'
user = 'xxx'
password = 'xxx'
commands = ['mkdir fuckyou']
result = login_windows(ip, user, password, commands)
print(result)