From 9b34714f0b1abad2cd5664bfeef8d2f016120195 Mon Sep 17 00:00:00 2001 From: Dave Date: Mon, 26 Feb 2024 20:22:01 -0500 Subject: [PATCH 1/2] add ipv6 to tcp_ping task --- nornir_utils/plugins/tasks/networking/tcp_ping.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/nornir_utils/plugins/tasks/networking/tcp_ping.py b/nornir_utils/plugins/tasks/networking/tcp_ping.py index ab19122..0bcba21 100644 --- a/nornir_utils/plugins/tasks/networking/tcp_ping.py +++ b/nornir_utils/plugins/tasks/networking/tcp_ping.py @@ -5,7 +5,7 @@ def tcp_ping( - task: Task, ports: List[int], timeout: int = 2, host: Optional[str] = None + task: Task, ports: List[int], timeout: int = 2, host: Optional[str] = None, ipv6: bool = False ) -> Result: """ Tests connection to a tcp port and tries to establish a three way @@ -36,7 +36,10 @@ def tcp_ping( result = {} for port in ports: - s = socket.socket() + if ipv6: + s = socket.socket(socket.AF_INET6) + else: + s = socket.socket() s.settimeout(timeout) try: status = s.connect_ex((host, port)) From 1805e6623e2adee94249046f9d40939b334d81ae Mon Sep 17 00:00:00 2001 From: Dave Date: Mon, 26 Feb 2024 20:26:14 -0500 Subject: [PATCH 2/2] add docstring for ipv6 setting --- nornir_utils/plugins/tasks/networking/tcp_ping.py | 1 + 1 file changed, 1 insertion(+) diff --git a/nornir_utils/plugins/tasks/networking/tcp_ping.py b/nornir_utils/plugins/tasks/networking/tcp_ping.py index 0bcba21..5a7cc3f 100644 --- a/nornir_utils/plugins/tasks/networking/tcp_ping.py +++ b/nornir_utils/plugins/tasks/networking/tcp_ping.py @@ -15,6 +15,7 @@ def tcp_ping( ports (list of int): tcp ports to ping timeout (int, optional): defaults to 2 host (string, optional): defaults to ``hostname`` + ipv6 (bool): use ipv6 socket. defaults to ``False`` Returns: