【问题标题】:How to connect to a VPS by Python? [duplicate]如何通过 Python 连接到 VPS? [复制]
【发布时间】:2019-11-29 09:32:28
【问题描述】:

我想编写一个程序来获取服务器列表(VPS)并检查服务器是否可用以及用户名和密码是否正确。所以我用谷歌搜索了一下,没有关于通过 python 连接到 VPS 的内容。 可能吗??如果是如何? 谢谢

【问题讨论】:

    标签: python vps rdp


    【解决方案1】:

    我假设你想通过 SSH 连接到 VPS。要在 Python 中做到这一点,您必须找到一个允许您建立 SSH 连接的模块。我建议 Paramiko 这样做。下面是一个关于如何连接到服务器的简单示例:

    import paramiko
    client = paramiko.SSHClient()
    client.load_system_host_keys()
    client.connect('ssh.example.com')
    stdin, stdout, stderr = client.exec_command('ls -l')
    

    或者如果您想改用用户名和密码:

    import paramiko
    client = paramiko.SSHClient()
    client.connect('ssh.example.com', username='root', password='toor')
    stdin, stdout, stderr = client.exec_command('ls -l')
    

    【讨论】:

    • 好吧,我有几个 Windows VPS,端口是 3389,用于 RDP。是否可以通过 ssh 连接到它们?
    • 好吧,我有几个 Windows VPS,端口是 3389,用于 RDP。是否可以通过 ssh 连接到它们?如果没有,有没有办法连接到windows VPS?
    • 你可以尝试使用github.com/citronneur/rdpy,但我建议你只在Windows上设置一个SSH服务器:bleepingcomputer.com/news/microsoft/…
    猜你喜欢
    • 2020-03-31
    • 2017-12-17
    • 1970-01-01
    • 1970-01-01
    • 2020-10-10
    • 1970-01-01
    • 2022-06-28
    • 2015-04-09
    • 2013-12-09
    相关资源
    最近更新 更多