伪造SSH服务器

fake-ssh的Python项目详细描述


模拟SSH服务器

你。。。在

  • 有一个SSHs到服务器的测试,不想设置一个测试的麻烦?在

  • 你觉得恶作剧不像听起来那么好?在

  • 想开发一个应用程序,需要一个假服务器来返回预定义的结果?在

这个包裹是给你的!在

安装

pip install fake-ssh

使用

阻止服务器

阻塞服务器通常用于开发目的。在

只需为自己编写一个server.py文件:

^{pr2}$

然后运行它:

$ python3 server.py

在单独的终端中,运行:

$ ssh root@127.0.0.1 -p 5050 echo 42
42
                                                                         
$ ssh root@127.0.0.1 -p 5050 ls
file1
file2

(如果系统提示您输入密码,您可以将其留空)

无阻塞服务器

测试中经常使用非阻塞服务器。在

此服务器在线程中运行,允许您并行运行一些测试。在

importparamikoimportpytestfromfake_sshimportServerdefhandler(command):ifcommand=="ls":return"file1\nfile2\n"@pytest.fixturedefserver():withServer(command_handler=handler)asserver:yieldserver@pytest.fixturedefclient(server):c=paramiko.SSHClient()c.set_missing_host_key_policy(paramiko.AutoAddPolicy())c.connect(hostname=server.host,port=server.port,username="root",password="",allow_agent=False,look_for_keys=False)returncdeftest_ls(client):_stdin,stdout,stderr=client.exec_command("ls")assertstdout.read().decode()=="file1\nfile2\n"

欢迎加入QQ群-->: 979659372 Python中文网_新手群

推荐PyPI第三方库


热门话题
用于批量操作的java RESTful API分块响应   java读取在线存储的文本文件   在Java ME中将双精度舍入到小数点后5位   java查找一个数字的最接近因子   java更改JMenuBar的字体   java Kmeans聚类算法运行时间和复杂性   java是否可以阻止try catch返回null   java内容解析器指向具有正确URI的错误表   java Android Kotlin插装测试未被识别为插装测试   java TestNG@Dataprovider   在forloop和print语句中声明变量时发生java错误   java在Android Studio 3中设置JNI