Skip to content

Commit 0278826

Browse files
committed
增加 telnetlib
1 parent f924371 commit 0278826

File tree

1 file changed

+32
-0
lines changed

1 file changed

+32
-0
lines changed

libs/python.wiki

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -749,6 +749,38 @@ Home:[https://bitbucket.org/jaraco/irc]
749749

750750
IRC 是 Internet Relay Chat 的缩写。这是用 Python 封装的第三方库。
751751

752+
=== 5.3.6 远程控制 ===
753+
754+
<h4>telnetlib</h4>
755+
756+
【标准库】
757+
758+
封装 telnet 协议
759+
760+
代码示例——使用 telnet 登录到某个主机并执行简单命令
761+
<source lang="python">
762+
import telnetlib
763+
import getpass
764+
765+
host = raw_input("Enter remote host: ")
766+
user = raw_input("Enter your remote account: ")
767+
password = getpass.getpass()
768+
769+
tn = telnetlib.Telnet(host)
770+
771+
tn.read_until("login: ")
772+
tn.write(user + "\n")
773+
774+
if password :
775+
tn.read_until("Password: ")
776+
tn.write(password + "\n")
777+
778+
tn.write("ls\n")
779+
tn.write("exit\n")
780+
781+
print tn.read_all()
782+
</source>
783+
752784
== 5.4 自定义的应用层 ==
753785

754786
<h4>Protocol Buffers</h4>

0 commit comments

Comments
 (0)