使用Python实现Telnet远程登录
by0x0021 2013-03-25
18:06:07
# -*- coding: utf-8 -*-
import telnetlib
'''Telnet远程登录:windows客户端连接linux服务器'''
# 配置选项
Host = '192.168.1.2' # Telnet服务器IP
sername = 'admin' # 登录用户名
passWord = '123456' # 登录密码
finish = ':~$ ' # 命令提示符(标识着上一条命令已执行完毕)
# 连接Telnet服务器
tn = telnetlib.Telnet(Host)
# 输入登录用户名
tn.read_until('login: ')
tn.write(username + '\n')
# 输入登录密码
tn.read_until('Password: ')
tn.write(password + '\n')
# 登录完毕后,执行ls命令
tn.read_until(finish)
tn.write('ls\n')
# ls命令执行完毕后,终止Telnet连接(或输入exit退出)
tn.read_until(finish)
tn.close() # tn.write('exit\n')
import telnetlib
'''Telnet远程登录:windows客户端连接linux服务器'''
# 配置选项
Host = '192.168.1.2' # Telnet服务器IP
sername = 'admin' # 登录用户名
passWord = '123456' # 登录密码
finish = ':~$ ' # 命令提示符(标识着上一条命令已执行完毕)
# 连接Telnet服务器
tn = telnetlib.Telnet(Host)
# 输入登录用户名
tn.read_until('login: ')
tn.write(username + '\n')
# 输入登录密码
tn.read_until('Password: ')
tn.write(password + '\n')
# 登录完毕后,执行ls命令
tn.read_until(finish)
tn.write('ls\n')
# ls命令执行完毕后,终止Telnet连接(或输入exit退出)
tn.read_until(finish)
tn.close() # tn.write('exit\n')
相关文章