Files
infix/test/infamy/netutil.py
Tobias Waldekranz 1d13c5ea9e test: infamy: Generalize netconf_syn() to test for any TCP service
Being able to check for a TCP based service is generally useful, not
only for NETCONF. Therefore, break it out to a separate function that
allows any port to be queried.
2025-01-22 20:16:47 +01:00

12 lines
291 B
Python

import socket
def tcp_port_is_open(host, port):
try:
ai = socket.getaddrinfo(host, port, 0, 0, socket.SOL_TCP)
sock = socket.socket(ai[0][0], ai[0][1], 0)
sock.connect(ai[0][4])
sock.close()
return True
except Exception:
return False