gpt4 book ai didi

windows - 使用Robot Framework扫描本地主机上的打开端口

转载 作者:行者123 更新时间:2023-12-03 11:11:52 24 4
gpt4 key购买 nike

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

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

什么是最合适的Robot Framework库,以获得所需的信息?

最佳答案

您可以使用机器人框架 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

关于windows - 使用Robot Framework扫描本地主机上的打开端口,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62021123/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com