面对python中的telnet.write()问题

时间:2017-02-19 03:57:31

标签: python sockets telnet

我从python文档中获得以下代码,在成功telnet(登录)到服务器后,我无法编写(telnet.write())。

我已用打印语句解码,请在下面找到详细信息:

import getpass
import sys
import telnetlib

HOST = "101.135.93.116"
user = raw_input("Enter your remote account login: ")
password = getpass.getpass()
tn = telnetlib.Telnet(HOST)

tn.read_until("login: ")   --> Upto here working fine able to read    **login** 


check = tn.write(user + "\n")
print "checking write --->", check     ----> Here it's printing **None** / Writing nothing here I want user login to be writen

if password:
    verify = tn.read_until("Password: ") 
    print "verify -->" ,verify          ---> able to read **Password**
    padecode = tn.write(password + "\n")
    print "passdecode--->",padecode     ---->  Here it's printing again **None** 


tn.write("ls\n")
tn.write("exit\n")

print tn.read_all()   ------> Not able to read anything not displaying anything

请注意

如果我假设write返回None,这意味着它成功获取凭证,那么为什么tn.read_all没有显示任何内容?

有人可以告诉我登录后如何正确写作......

提前致谢

0 个答案:

没有答案