- 论坛徽章:
- 0
|
本帖最后由 sinxadmin 于 2011-06-03 14:18 编辑
大家好!- import getpass
- import time
- import sys
- import telnetlib
- HOST = "localhost"
- PORT = 1981
- user = raw_input("Enter your remote account: ")
- password = getpass.getpass()
- tn = telnetlib.Telnet(HOST,PORT)
- try:
- tn.read_until("username: ")
- except EOFError:
- print 'username:error'
- tn.write(user + '\n')
- if password:
- try:
- tn.read_until("password: ",30)
- except EOFError:
- print 'password:error'
- print password
- tn.write(password+'\n')
- tn.write("help\n")
- tn.write("exit\n")
- print tn.read_all()
复制代码 # python telnet.py
Enter your remote account: admin
Password:
password:error
123456
tn.read_until("password: ",30)这里报的异常,是tn.write(user + '\n')没有发送成功吗?
>telnet localhost 1981
username: admin
password:
[]# |
|