【问题标题】:How to setup telnet server in python如何在python中设置telnet服务器
【发布时间】:2022-01-21 00:32:30
【问题描述】:

如何在 python 中构建 telnet 服务器?我应该使用什么工具? 我在互联网上看到了很多代码,但没有任何效果。 它需要在没有登录提示的情况下将 python 文件作为 shell 运行。 我该怎么做?

【问题讨论】:

    标签: python telnet


    【解决方案1】:

    telnetlib 模块提供了一个实现 Telnet 协议的 Telnet 类。

    说明典型用法的简单示例:

    import getpass
    import telnetlib
    
    HOST = "localhost"
    user = input("Enter your remote account: ")
    password = getpass.getpass()
    
    tn = telnetlib.Telnet(HOST)
    
    tn.read_until(b"login: ")
    tn.write(user.encode('ascii') + b"\n")
    if password:
        tn.read_until(b"Password: ")
        tn.write(password.encode('ascii') + b"\n")
    
    tn.write(b"ls\n")
    tn.write(b"exit\n")
    
    print(tn.read_all().decode('ascii'))
    

    更多细节:

    https://docs.python.org/3/library/telnetlib.html

    要安装库,请输入以下命令:

    pip install telnetlib3
    

    【讨论】:

    • 此脚本似乎连接到服务器。但我想要一个托管服务器的脚本。
    猜你喜欢
    • 2010-10-24
    • 2013-06-20
    • 2021-04-07
    • 2011-12-30
    • 2011-03-25
    • 2014-06-27
    • 1970-01-01
    • 2013-02-17
    • 2019-10-16
    相关资源
    最近更新 更多