mirror of
https://github.com/kernelkit/infix.git
synced 2026-07-30 20:43:02 +02:00
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.
12 lines
291 B
Python
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
|