diff --git a/nornir_utils/plugins/tasks/networking/tcp_ping.py b/nornir_utils/plugins/tasks/networking/tcp_ping.py index ab19122..5a7cc3f 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 @@ -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: @@ -36,7 +37,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))