patrickw
New Contributor II

Thank you Walter_C. I ran a similar block of code utilizing the shell command you provide. 

Code

import subprocess

# Define the hostname and port
hostname = "************"
port = "1433"

# Create the command as a list
command = ["nc", "-vz", hostname, port]

# Execute the command and capture the output and errors
process = subprocess.run(command, text=True, capture_output=True)

# Check if the process was successful
if process.returncode == 0:
    print("Connection successful.")
else:
    print("Failed to connect.")
    print("Output:", process.stdout)
    print("Errors:", process.stderr)

 

And I got this output:

Failed to connect. Output: Errors: nc: connect to ************** (ip address) port 1433 (tcp) failed: Connection timed out

I have consulted with my system admin and he confirmed that the port and firewall were open. In this example, I attempted to execute code like this while the admin was monitoring the firewall activity and he did not see anything attempt to access and get blocked. Now when I ran a ping command he could see the IP from the cluster in the activity log.