tcp_ping

Tests connection to a TCP port trying to establish a three way handshake. Useful for network discovery or testing.

tcp_ping sample usage

Sample code to run tcp_ping task:

import pprint
from nornir import InitNornir
from nornir_salt.plugins.tasks import tcp_ping
from nornir_salt.plugins.functions import ResultSerializer

nr = InitNornir(config_file="config.yaml")

result = NornirObj.run(
    task=tcp_ping,
    ports=[22]
)

result_dictionary = ResultSerializer(result)

pprint.pprint(result_dictionary)

# prints:
#
# {'IOL1': {'tcp_ping': {22: True}},
#  'IOL2': {'tcp_ping': {22: True}}}

tcp_ping returns

Returns dictionary of port numbers as keys with True/False as values

tcp_ping reference

nornir_salt.plugins.tasks.tcp_ping.tcp_ping(task: nornir.core.task.Task, ports: List[int] = [], timeout: int = 1, host: Optional[str] = None) nornir.core.task.Result
Parameters
  • ports – list of int, optional, tcp ports to ping, defaults to host’s port or 22

  • timeout – int, optional, connection timeout, defaults to 1

  • host – string, optional, address to TCP ping, defaults to hosts’s hostname value

Returns

dictionary of port numbers as keys with True/False as values