Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Feat]: use ipv6 socket in tcp_ping task #38

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions nornir_utils/plugins/tasks/networking/tcp_ping.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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:
Expand All @@ -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))
Expand Down
Loading