当前位置: 首页>>代码示例>>Python>>正文


Python Hornet.stop方法代码示例

本文整理汇总了Python中hornet.main.Hornet.stop方法的典型用法代码示例。如果您正苦于以下问题:Python Hornet.stop方法的具体用法?Python Hornet.stop怎么用?Python Hornet.stop使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在hornet.main.Hornet的用法示例。


在下文中一共展示了Hornet.stop方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: test_shell_set_host

# 需要导入模块: from hornet.main import Hornet [as 别名]
# 或者: from hornet.main.Hornet import stop [as 别名]
    def test_shell_set_host(self):
        """ Tests if host related attributes are set on the shell properly """

        honeypot = Hornet(self.working_dir)
        honeypot.start()
        while honeypot.server.server_port == 0:  # wait until the server is ready
            gevent.sleep(0)
        port = honeypot.server.server_port
        client = paramiko.SSHClient()
        client.set_missing_host_key_policy(paramiko.AutoAddPolicy())
        # If we log in properly, this should raise no errors
        client.connect('127.0.0.1', port=port, username='testuser', password='testpassword')
        channel = client.invoke_shell()

        while not channel.recv_ready():
            gevent.sleep(0)  # :-(

        welcome = ''
        while channel.recv_ready():
            welcome += channel.recv(1)
        lines = welcome.split('\r\n')
        prompt = lines[-1]
        username, remaining = prompt.split('@')
        self.assertEquals(username, 'testuser')
        hostname, remaining = remaining.split(':')
        self.assertEquals(hostname, 'test02')
        self.assertTrue(prompt.endswith('$ '))
        honeypot.stop()
开发者ID:czardoz,项目名称:hornet,代码行数:30,代码来源:test_host.py

示例2: test_ls_long_backref

# 需要导入模块: from hornet.main import Hornet [as 别名]
# 或者: from hornet.main.Hornet import stop [as 别名]
    def test_ls_long_backref(self):
        """ Test basic 'ls -l .. var' with multiple directory arguments """

        honeypot = Hornet(self.working_dir)
        honeypot.start()
        self.create_filesystem(honeypot)

        while honeypot.server.server_port == 0:  # wait until the server is ready
            gevent.sleep(0)
        port = honeypot.server.server_port
        client = paramiko.SSHClient()
        client.set_missing_host_key_policy(paramiko.AutoAddPolicy())
        # If we log in properly, this should raise no errors
        client.connect('127.0.0.1', port=port, username='testuser', password='testpassword')
        channel = client.invoke_shell()

        while not channel.recv_ready():
            gevent.sleep(0)  # :-(

        welcome = ''
        while channel.recv_ready():
            welcome += channel.recv(1)
        lines = welcome.split('\r\n')
        prompt = lines[-1]
        self.assertTrue(prompt.endswith('$ '))

        # Now send the ls command
        ls_command = 'ls -l .. var'
        channel.send(ls_command + '\r\n')

        while not channel.recv_ready():
            gevent.sleep(0)  # :-(

        output = ''
        while not output.endswith('$ '):
            output += channel.recv(1)

        lines = output.split('\r\n')
        command = lines[0]
        command_output = '\r\n'.join(lines[1:-1])
        next_prompt = lines[-1]

        self.assertEquals(command, ls_command)
        dir_outputs = sorted(command_output.split('\r\n\r\n'))

        self.assertTrue(dir_outputs[0].startswith('..:'))
        self.assertTrue('total ' in dir_outputs[0])
        self.assertTrue('var' in dir_outputs[0])
        self.assertTrue('bin' in dir_outputs[0])
        self.assertTrue('initrd.img' in dir_outputs[0])
        self.assertTrue('etc' in dir_outputs[0])
        self.assertEquals(len(dir_outputs[0].split('\r\n')), 6)

        self.assertTrue(dir_outputs[1].startswith('var:'))
        self.assertTrue('total 0' in dir_outputs[1])
        self.assertEquals(len(dir_outputs[1].split('\r\n')), 2)

        self.assertTrue(next_prompt.endswith('$ '))

        honeypot.stop()
开发者ID:czardoz,项目名称:hornet,代码行数:62,代码来源:test_ls.py

示例3: test_ifconfig

# 需要导入模块: from hornet.main import Hornet [as 别名]
# 或者: from hornet.main.Hornet import stop [as 别名]
    def test_ifconfig(self):
        """ Tests if ifconfig command works """

        honeypot = Hornet(self.working_dir)
        honeypot.start()
        self.create_filesystem(honeypot)

        while honeypot.server.server_port == 0:  # wait until the server is ready
            gevent.sleep(0)
        port = honeypot.server.server_port
        client = paramiko.SSHClient()
        client.set_missing_host_key_policy(paramiko.AutoAddPolicy())
        # If we log in properly, this should raise no errors
        client.connect('127.0.0.1', port=port, username='testuser', password='testpassword')
        channel = client.invoke_shell()

        while not channel.recv_ready():
            gevent.sleep(0)  # :-(

        welcome = ''
        while channel.recv_ready():
            welcome += channel.recv(1)
        lines = welcome.split('\r\n')
        prompt = lines[-1]
        self.assertTrue(prompt.endswith('$ '))

        # Now send the cd command
        cd_command = 'ifconfig'
        channel.send(cd_command + '\r\n')

        while not channel.recv_ready():
            gevent.sleep(0)  # :-(

        output = ''
        while not output.endswith('$ '):
            output += channel.recv(1)

        lines = output.split('\r\n')
        command = lines[0]
        command_output = '\r\n'.join(lines[1:-1])
        next_prompt = lines[-1]

        self.assertEquals(command, cd_command)
        interfaces = sorted(command_output.split('\r\n\r\n'))
        self.assertTrue(interfaces[0].startswith('eth0 '))
        self.assertTrue('HWaddr 00:16:3e:76:35:d1' in interfaces[0])
        self.assertTrue('inet addr:192.168.0.232 ' in interfaces[0])
        self.assertTrue('Bcast:192.168.0.255 ' in interfaces[0])
        self.assertTrue('Mask:255.255.255.0' in interfaces[0])

        self.assertTrue(interfaces[1].startswith('lo '))
        self.assertTrue('inet addr:127.0.0.1 ' in interfaces[1])
        self.assertTrue('Mask:255.0.0.0' in interfaces[1])

        self.assertTrue(next_prompt.endswith('$ '))

        honeypot.stop()
开发者ID:czardoz,项目名称:hornet,代码行数:59,代码来源:test_ifconfig.py

示例4: test_basic_ls_all_with_multiple_dir_args

# 需要导入模块: from hornet.main import Hornet [as 别名]
# 或者: from hornet.main.Hornet import stop [as 别名]
    def test_basic_ls_all_with_multiple_dir_args(self):
        """ Test basic 'ls -a etc var' """

        honeypot = Hornet(self.working_dir)
        honeypot.start()
        self.create_filesystem(honeypot)

        while honeypot.server.server_port == 0:  # wait until the server is ready
            gevent.sleep(0)
        port = honeypot.server.server_port
        client = paramiko.SSHClient()
        client.set_missing_host_key_policy(paramiko.AutoAddPolicy())
        # If we log in properly, this should raise no errors
        client.connect('127.0.0.1', port=port, username='testuser', password='testpassword')
        channel = client.invoke_shell()

        while not channel.recv_ready():
            gevent.sleep(0)  # :-(

        welcome = ''
        while channel.recv_ready():
            welcome += channel.recv(1)
        lines = welcome.split('\r\n')
        prompt = lines[-1]
        self.assertTrue(prompt.endswith('$ '))

        # Now send the ls command
        ls_command = 'ls -a etc var'
        channel.send(ls_command + '\r\n')

        while not channel.recv_ready():
            gevent.sleep(0)  # :-(

        output = ''
        while not output.endswith('$ '):
            output += channel.recv(1)

        lines = output.split('\r\n')
        command = lines[0]
        command_output = '\r\n'.join(lines[1:-1])
        next_prompt = lines[-1]

        dir_outputs = sorted(command_output.split('\r\n\r\n'))

        self.assertEquals(command, ls_command)
        self.assertTrue('passwd' in dir_outputs[0])
        self.assertTrue('.config' in dir_outputs[0])
        self.assertTrue('. ' in dir_outputs[0])
        self.assertTrue('..' in dir_outputs[0])
        self.assertTrue('init.d' in dir_outputs[0])
        self.assertTrue('sysctl.conf' in dir_outputs[0])

        self.assertTrue("var:" in dir_outputs[1])

        self.assertTrue(next_prompt.endswith('$ '))

        honeypot.stop()
开发者ID:czardoz,项目名称:hornet,代码行数:59,代码来源:test_ls.py

示例5: test_vfs_creation

# 需要导入模块: from hornet.main import Hornet [as 别名]
# 或者: from hornet.main.Hornet import stop [as 别名]
    def test_vfs_creation(self):
        """ Tests whether virtual file systems for each host are created """

        honeypot = Hornet(self.working_dir)
        honeypot.start()
        vfs_dir = os.path.join(self.working_dir, 'vhosts')
        self.assertTrue(os.path.isdir(vfs_dir))
        for item in os.listdir(vfs_dir):
            self.assertTrue(item.startswith('test'))
        honeypot.stop()
开发者ID:czardoz,项目名称:hornet,代码行数:12,代码来源:test_hornet.py

示例6: test_ifconfig_help_param

# 需要导入模块: from hornet.main import Hornet [as 别名]
# 或者: from hornet.main.Hornet import stop [as 别名]
    def test_ifconfig_help_param(self):
        """ Tests if 'ifconfig --help' works """

        honeypot = Hornet(self.working_dir)
        honeypot.start()
        self.create_filesystem(honeypot)

        while honeypot.server.server_port == 0:  # wait until the server is ready
            gevent.sleep(0)
        port = honeypot.server.server_port
        client = paramiko.SSHClient()
        client.set_missing_host_key_policy(paramiko.AutoAddPolicy())
        # If we log in properly, this should raise no errors
        client.connect('127.0.0.1', port=port, username='testuser', password='testpassword')
        channel = client.invoke_shell()

        while not channel.recv_ready():
            gevent.sleep(0)  # :-(

        welcome = ''
        while channel.recv_ready():
            welcome += channel.recv(1)
        lines = welcome.split('\r\n')
        prompt = lines[-1]
        self.assertTrue(prompt.endswith('$ '))

        # Now send the ifconfig command
        ifconfig_command = 'ifconfig --help'
        channel.send(ifconfig_command + '\r\n')

        while not channel.recv_ready():
            gevent.sleep(0)  # :-(

        output = ''
        while not output.endswith('$ '):
            output += channel.recv(1)

        lines = output.split('\r\n')
        command = lines[0]
        command_output = '\r\n'.join(lines[1:-1])
        next_prompt = lines[-1]

        expected_output = []
        help_file_path = os.path.join(os.path.dirname(hornet.__file__), 'data',
                                      'commands', 'ifconfig', 'help')
        with open(help_file_path) as help_file:
            for line in help_file:
                line = line.strip()
                expected_output.append(line)

        self.assertEquals(command, ifconfig_command)
        self.assertEquals(command_output, '\r\n'.join(expected_output))
        self.assertTrue(next_prompt.endswith('$ '))

        honeypot.stop()
开发者ID:czardoz,项目名称:hornet,代码行数:57,代码来源:test_ifconfig.py

示例7: test_wget_bad_content_length

# 需要导入模块: from hornet.main import Hornet [as 别名]
# 或者: from hornet.main.Hornet import stop [as 别名]
    def test_wget_bad_content_length(self):
        """ Tests if 'wget http://pathod.net/response_preview?spec=200%3Ar%3Ah%22Content-Length
        %22%3D%22%27unparsable%22' shows an error resolving """

        honeypot = Hornet(self.working_dir)
        honeypot.start()

        while honeypot.server.server_port == 0:  # wait until the server is ready
            gevent.sleep(0)
        port = honeypot.server.server_port
        client = paramiko.SSHClient()
        client.set_missing_host_key_policy(paramiko.AutoAddPolicy())
        # If we log in properly, this should raise no errors
        client.connect('127.0.0.1', port=port, username='testuser', password='testpassword')
        channel = client.invoke_shell()

        while not channel.recv_ready():
            gevent.sleep(0)  # :-(

        welcome = ''
        while channel.recv_ready():
            welcome += channel.recv(1)
        lines = welcome.split('\r\n')
        prompt = lines[-1]
        self.assertTrue(prompt.endswith('$ '))

        # Now send the wget command
        wget_command = 'wget http://pathod.net/response_preview?spec=200%3Ar%3Ah%22' \
                       'Content-Length%22%3D%22%27unparsable%22'
        channel.send(wget_command + '\r\n')

        while not channel.recv_ready():
            gevent.sleep(0)  # :-(

        output = ''
        while not output.endswith('$ '):
            output += channel.recv(1)

        lines = output.split('\r\n')
        command = lines[0]
        next_prompt = lines[-1]

        self.assertEquals(command, wget_command)

        self.assertTrue(lines[1].startswith('--'))
        self.assertTrue('http://pathod.net/response_preview?spec=200%3Ar%3Ah%22'
                        'Content-Length%22%3D%22%27unparsable%22' in lines[1])
        self.assertEquals('Resolving pathod.net (pathod.net)... '
                          'failed: Name or service not known.', lines[2])
        self.assertEquals('wget: unable to resolve host address \'pathod.net\'', lines[3])
        self.assertTrue(next_prompt.endswith('$ '))
        honeypot.stop()
开发者ID:czardoz,项目名称:hornet,代码行数:54,代码来源:test_wget.py

示例8: test_uname_with_params

# 需要导入模块: from hornet.main import Hornet [as 别名]
# 或者: from hornet.main.Hornet import stop [as 别名]
    def test_uname_with_params(self):
        """ Tests if 'uname -a' command works """

        honeypot = Hornet(self.working_dir)
        honeypot.start()
        self.create_filesystem(honeypot)

        while honeypot.server.server_port == 0:  # wait until the server is ready
            gevent.sleep(0)
        port = honeypot.server.server_port
        client = paramiko.SSHClient()
        client.set_missing_host_key_policy(paramiko.AutoAddPolicy())
        # If we log in properly, this should raise no errors
        client.connect('127.0.0.1', port=port, username='testuser', password='testpassword')
        channel = client.invoke_shell()

        while not channel.recv_ready():
            gevent.sleep(0)  # :-(

        welcome = ''
        while channel.recv_ready():
            welcome += channel.recv(1)
        lines = welcome.split('\r\n')
        prompt = lines[-1]
        self.assertTrue(prompt.endswith('$ '))

        # Now send the cd command
        uname_command = 'uname -a'
        channel.send(uname_command + '\r\n')

        while not channel.recv_ready():
            gevent.sleep(0)  # :-(

        output = ''
        while not output.endswith('$ '):
            output += channel.recv(1)

        lines = output.split('\r\n')
        command = lines[0]
        command_output = '\r\n'.join(lines[1:-1])
        next_prompt = lines[-1]

        expected_info = ['Linux', honeypot.config.default_hostname, '3.13.0-37-generic',
                         '#64-Ubuntu SMP Mon Sep 22 21:30:01 UTC 2014', 'i686',
                         'i686', 'i686', 'GNU/Linux']

        self.assertEquals(command, uname_command)
        self.assertEquals(command_output, ' '.join(expected_info))
        self.assertTrue(next_prompt.endswith('$ '))

        honeypot.stop()
开发者ID:czardoz,项目名称:hornet,代码行数:53,代码来源:test_uname.py

示例9: test_login_success

# 需要导入模块: from hornet.main import Hornet [as 别名]
# 或者: from hornet.main.Hornet import stop [as 别名]
    def test_login_success(self):
        """ Tests whether an SSH client can login to the Honeypot """

        honeypot = Hornet(self.working_dir)
        honeypot.start()
        while honeypot.server.server_port == 0:  # wait until the server is ready
            gevent.sleep(0)
        port = honeypot.server.server_port
        client = paramiko.SSHClient()
        client.set_missing_host_key_policy(paramiko.AutoAddPolicy())
        # If we log in properly, this should raise no errors
        client.connect('127.0.0.1', port=port, username='testuser', password='testpassword')
        gevent.sleep(1)
        honeypot.stop()
开发者ID:czardoz,项目名称:hornet,代码行数:16,代码来源:test_hornet.py

示例10: test_ls_ld

# 需要导入模块: from hornet.main import Hornet [as 别名]
# 或者: from hornet.main.Hornet import stop [as 别名]
    def test_ls_ld(self):
        """ Test basic 'ls -ld var bin etc/passwd initrd.img' with files as well as directories """

        honeypot = Hornet(self.working_dir)
        honeypot.start()
        self.create_filesystem(honeypot)

        while honeypot.server.server_port == 0:  # wait until the server is ready
            gevent.sleep(0)
        port = honeypot.server.server_port
        client = paramiko.SSHClient()
        client.set_missing_host_key_policy(paramiko.AutoAddPolicy())
        # If we log in properly, this should raise no errors
        client.connect('127.0.0.1', port=port, username='testuser', password='testpassword')
        channel = client.invoke_shell()

        while not channel.recv_ready():
            gevent.sleep(0)  # :-(

        welcome = ''
        while channel.recv_ready():
            welcome += channel.recv(1)
        lines = welcome.split('\r\n')
        prompt = lines[-1]
        self.assertTrue(prompt.endswith('$ '))

        # Now send the ls command
        ls_command = 'ls -ld var bin etc/passwd initrd.img'
        channel.send(ls_command + '\r\n')

        while not channel.recv_ready():
            gevent.sleep(0)  # :-(

        output = ''
        while not output.endswith('$ '):
            output += channel.recv(1)

        lines = output.split('\r\n')
        command = lines[0]
        command_output = '\r\n'.join(lines[1:-1])
        next_prompt = lines[-1]

        self.assertEquals(command, ls_command)
        actual_list = command_output.split('\r\n')
        expected_list = ['initrd.img', 'var', 'passwd', 'bin']
        self.verify_long_list(actual_list, expected_list)
        self.assertTrue('total' not in command_output)
        self.assertTrue(next_prompt.endswith('$ '))

        honeypot.stop()
开发者ID:czardoz,项目名称:hornet,代码行数:52,代码来源:test_ls.py

示例11: test_wget_bad_hostname

# 需要导入模块: from hornet.main import Hornet [as 别名]
# 或者: from hornet.main.Hornet import stop [as 别名]
    def test_wget_bad_hostname(self):
        """ Tests if 'wget http://asdjkhaskdh/index.html' works (bad hostname case) """

        honeypot = Hornet(self.working_dir)
        honeypot.start()

        while honeypot.server.server_port == 0:  # wait until the server is ready
            gevent.sleep(0)
        port = honeypot.server.server_port
        client = paramiko.SSHClient()
        client.set_missing_host_key_policy(paramiko.AutoAddPolicy())
        # If we log in properly, this should raise no errors
        client.connect('127.0.0.1', port=port, username='testuser', password='testpassword')
        channel = client.invoke_shell()

        while not channel.recv_ready():
            gevent.sleep(0)  # :-(

        welcome = ''
        while channel.recv_ready():
            welcome += channel.recv(1)
        lines = welcome.split('\r\n')
        prompt = lines[-1]
        self.assertTrue(prompt.endswith('$ '))

        # Now send the wget command
        wget_command = 'wget http://asdjkhaskdh/index.html'
        channel.send(wget_command + '\r\n')

        while not channel.recv_ready():
            gevent.sleep(0)  # :-(

        output = ''
        while not output.endswith('$ '):
            output += channel.recv(1)

        lines = output.split('\r\n')
        command = lines[0]
        next_prompt = lines[-1]

        self.assertEquals(command, wget_command)

        self.assertTrue(lines[1].startswith('--'))
        self.assertTrue('http://asdjkhaskdh/index.html' in lines[1])
        self.assertEquals('Resolving asdjkhaskdh (asdjkhaskdh)... '
                          'failed: Name or service not known.', lines[2])
        self.assertEquals('wget: unable to resolve host address \'asdjkhaskdh\'', lines[3])
        self.assertTrue(next_prompt.endswith('$ '))

        honeypot.stop()
开发者ID:czardoz,项目名称:hornet,代码行数:52,代码来源:test_wget.py

示例12: test_login_failure

# 需要导入模块: from hornet.main import Hornet [as 别名]
# 或者: from hornet.main.Hornet import stop [as 别名]
    def test_login_failure(self):
        """ Tests whether an SSH client login fails on bad credentials """

        honeypot = Hornet(self.working_dir)
        honeypot.start()
        while honeypot.server.server_port == 0:  # wait until the server is ready
            gevent.sleep(0)
        port = honeypot.server.server_port
        client = paramiko.SSHClient()
        client.set_missing_host_key_policy(paramiko.AutoAddPolicy())
        with self.assertRaises(paramiko.AuthenticationException):
            client.connect('127.0.0.1', port=port, username='aksjd', password='asjdhkasd')
        gevent.sleep(1)
        honeypot.stop()
开发者ID:czardoz,项目名称:hornet,代码行数:16,代码来源:test_hornet.py

示例13: test_key_creation

# 需要导入模块: from hornet.main import Hornet [as 别名]
# 或者: from hornet.main.Hornet import stop [as 别名]
    def test_key_creation(self):
        """ Tests if key file is generated on run """

        honeypot = Hornet(self.working_dir)
        honeypot.start()
        while honeypot.server.server_port == 0:  # wait until the server is ready
            gevent.sleep(0)
        port = honeypot.server.server_port
        client = paramiko.SSHClient()
        client.set_missing_host_key_policy(paramiko.AutoAddPolicy())
        client.connect('127.0.0.1', port=port, username='testuser', password='testpassword')
        # Add a sleep here if this test fails for no reason... the server needs time to write the key file
        # gevent.sleep(1)
        self.assertTrue(os.path.isfile(os.path.join(self.working_dir, 'test_server.key')))
        honeypot.stop()
开发者ID:czardoz,项目名称:hornet,代码行数:17,代码来源:test_hornet.py

示例14: test_ping_multiple_hosts

# 需要导入模块: from hornet.main import Hornet [as 别名]
# 或者: from hornet.main.Hornet import stop [as 别名]
    def test_ping_multiple_hosts(self):
        """ Tests basic 'ping lolwakaka awasd'
            Makes sure the last param is picked up as the host to ping.
        """

        honeypot = Hornet(self.working_dir)
        honeypot.start()

        while honeypot.server.server_port == 0:  # wait until the server is ready
            gevent.sleep(0)
        port = honeypot.server.server_port
        client = paramiko.SSHClient()
        client.set_missing_host_key_policy(paramiko.AutoAddPolicy())
        # If we log in properly, this should raise no errors
        client.connect('127.0.0.1', port=port, username='testuser', password='testpassword')
        channel = client.invoke_shell()

        while not channel.recv_ready():
            gevent.sleep(0)  # :-(

        welcome = ''
        while channel.recv_ready():
            welcome += channel.recv(1)
        lines = welcome.split('\r\n')
        prompt = lines[-1]
        self.assertTrue(prompt.endswith('$ '))

        # Now send the ping command
        ping_command = 'ping lolwakaka awasd'
        channel.send(ping_command + '\r\n')

        while not channel.recv_ready():
            gevent.sleep(0)  # :-(

        output = ''
        while not output.endswith('$ '):
            output += channel.recv(1)

        lines = output.split('\r\n')
        command = lines[0]
        command_output = '\r\n'.join(lines[1:-1])
        next_prompt = lines[-1]

        self.assertEquals(command, ping_command)
        self.assertEquals(command_output, 'ping: unknown host awasd')
        self.assertTrue(next_prompt.endswith('$ '))

        honeypot.stop()
开发者ID:czardoz,项目名称:hornet,代码行数:50,代码来源:test_ping.py

示例15: test_ls_l_non_existant_path

# 需要导入模块: from hornet.main import Hornet [as 别名]
# 或者: from hornet.main.Hornet import stop [as 别名]
    def test_ls_l_non_existant_path(self):
        """ Test basic 'ls -l nonexistantpath' with non-existant path argument """

        honeypot = Hornet(self.working_dir)
        honeypot.start()
        self.create_filesystem(honeypot)

        while honeypot.server.server_port == 0:  # wait until the server is ready
            gevent.sleep(0)
        port = honeypot.server.server_port
        client = paramiko.SSHClient()
        client.set_missing_host_key_policy(paramiko.AutoAddPolicy())
        # If we log in properly, this should raise no errors
        client.connect('127.0.0.1', port=port, username='testuser', password='testpassword')
        channel = client.invoke_shell()

        while not channel.recv_ready():
            gevent.sleep(0)  # :-(

        welcome = ''
        while channel.recv_ready():
            welcome += channel.recv(1)
        lines = welcome.split('\r\n')
        prompt = lines[-1]
        self.assertTrue(prompt.endswith('$ '))

        # Now send the ls command
        ls_command = 'ls -l nonexistantpath'
        channel.send(ls_command + '\r\n')

        while not channel.recv_ready():
            gevent.sleep(0)  # :-(

        output = ''
        while not output.endswith('$ '):
            output += channel.recv(1)

        lines = output.split('\r\n')
        command = lines[0]
        command_output = '\r\n'.join(lines[1:-1])
        next_prompt = lines[-1]

        self.assertEquals(command, ls_command)
        self.assertEquals(command_output, 'ls: cannot access nonexistantpath: No such file or directory')
        self.assertTrue(next_prompt.endswith('$ '))

        honeypot.stop()
开发者ID:czardoz,项目名称:hornet,代码行数:49,代码来源:test_ls.py


注:本文中的hornet.main.Hornet.stop方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。