使用 Robot Framework 扫描本地主机上的开放端口

Using Robot Framework to scan for open ports on localhost

我正在使用 Robot Framework 来测试网络问题和服务器。我在 windows 环境中。

现在,我需要测试某个服务是否在某个端口的本地主机上可用。我可以将 netstat 与 Process 库一起使用来确定所需的服务是否在指定端口上 运行,但这似乎有点笨拙。

什么可能是最适合获取所需信息的机器人框架库?

您可以使用机器人框架 SSHLibrary (http://robotframework.org/SSHLibrary/SSHLibrary.html)

下面的示例展示了如何在 192.168.10.10 主机中为端口 8082 创建 ssh 隧道并将 8082 端口映射到本地计算机中的 8083

*** Settings ***
Documentation          This example demonstrates executing a command on a remote machine
...                    and getting its output.
...
...                    Notice how connections are handled as part of the suite setup and
...                    teardown. This saves some time when executing several test cases.

Library                SSHLibrary
Suite Setup            Open Connection And Log In
Suite Teardown         Close All Connections

*** Variables ***
${HOST}                192.168.10.10
${USERNAME}            username
${PASSWORD}            Password

*** Test Cases ***
Execute Command And Verify Output
    [Documentation]    Execute Command can be used to run commands on the remote machine.
    ...                The keyword returns the standard output by default.
    ${output}=         Execute Command    echo Hello SSHLibrary!
    Should Be Equal    ${output}          Hello SSHLibrary!

*** Keywords ***
Open Connection And Log In
   Open Connection     ${HOST}
   Login               ${USERNAME}        ${PASSWORD}
   create local ssh tunnel  8083  ${HOST}  8082  #source_port  host_ip  destination_port