【问题标题】:Using Robot Framework to scan for open ports on localhost使用 Robot Framework 扫描本地主机上的开放端口
【发布时间】:2020-05-26 11:27:41
【问题描述】:
我正在使用 Robot Framework 来测试网络问题和服务器。我在windows环境下。
现在,我需要测试某个服务是否在某个端口的 localhost 上可用。我可以使用 netstat 和 Process 库来确定所需的服务是否在指定端口上运行,但这似乎有点笨拙。
什么可能是最适合获得所需信息的 Robot Framework 库?
【问题讨论】:
标签:
windows
robotframework
netstat
port-scanning
【解决方案1】:
您可以使用机器人框架 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