I am attempting to perform a health check on a specific port and ip of a private ec2 instance inside a vpc.
How would I go about this? I made some python attempts but have been unsuccessful so far. Would nodejs be a better alternative for this problem?
You can use the module socket
import socket
IP = '127.0.0.1'
PORT = 80
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
result = sock.connect_ex((IP,PORT))
if result == 0:
print(f'Port {PORT} is open on {IP}')
else:
print(f'Port {PORT} is closed on {IP}')