+ -
当前位置:首页 → 问答吧 → telnetlib read_until

telnetlib read_until

时间:2011-04-12

来源:互联网

用python写了一个脚本如下:

    #!/usr/bin/python

    import telnetlib,time

    host='remotehost'
    user = 'test'
    pwd = 'test'

    tn = telnetlib.Telnet(host)
    tn.set_debuglevel('9')

    tn.read_until("login: ", 10)
    tn.write(user + '\n')
    print tn.read_until("Password: ", 3)
    tn.write(pwd + '\n')
    tn.read_until("$", 1)
    tn.write("cd / \n")
    tn.write("ls \n")

    print tn.read_until("ls \n", 10)
    print tn.read_until("$", 1)

复制代码
当我打印出read_until时,为什么大数情况下没有command,结果如下:
[test@localhost ~]$ [test@localhost /]$ usr lib proc
bin                     proc      
boot                     lost+found  root          var
                    media       sbin      

很少会有这样的结果:
cd /
ls
Last login: Tue Jan 11 04:35:28
[test@localhost ~]$ cd /
[test@localhost /]$ ls
bin                       lib         proc          usr
boot                      lost+found  root          var
b media       sbin     
[test@localhost /]$

作者: leve1031   发布时间: 2011-04-12

回复 leve1031
怎么都没人回我呀。我打出telnet的debug信息,当不显示command的时候有这样一条
Telnet(remotehost,23): recv 'on an i686\r\n'
Telnet(remotehost,23): recv '\xf2'
Telnet(remotehost,23): recv 'login: '
这条是什么意思呀?

作者: leve1031   发布时间: 2011-04-12