嗨,我知道我应该发送“IAC DONT ECHO”消息,但是我该如何使用 telnetlib 呢?这是我的测试,但它不起作用。
#!/usr/bin/env python2
u"""test"""
# -*- coding: utf-8 -*-
import sys
import telnetlib
import time
HOST = "10.10.5.1"
tn = telnetlib.Telnet(HOST, timeout=1)
tn.read_until("login: ")
tn.write("login\n")
tn.read_until("Password: ")
tn.write("pass\n")
print "###########"
time.sleep(0.5)
print tn.read_very_eager()
tn.write("ls /\n")
time.sleep(0.5)
print tn.read_very_eager()
# diable echo here
tn.write(telnetlib.IAC + "\n")
tn.write(telnetlib.DONT + " " + telnetlib.ECHO + "\n")
time.sleep(0.5)
print tn.read_very_eager()
tn.write("ls /\n")
time.sleep(0.5)
print tn.read_very_eager()
print "########### exit"
tn.write("exit\n")
print tn.read_all()