Search code examples
windowsrobotframeworknetstatport-scanning

Using Robot Framework to scan for open ports on localhost


I'm using Robot Framework to test network issues and servers. I'm on a windows environment.

Right now, I'm in need to test if a certain service is available on localhost on a certain port. I could use netstat together with the Process library to figure out if the desired service is running on the designated port, but this seems to be a bit clumsy.

What might be a best suited Robot Framework library, to obtain the desired information?


Solution

  • You can do this by using robot framework SSHLibrary (http://robotframework.org/SSHLibrary/SSHLibrary.html)

    Below example shows how to create ssh tunnel for port 8082 in the 192.168.10.10 host and map the 8082 port to 8083 in the local machine

    *** 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