Would you like to learn how to test the TCP port connectivity using Python? In this tutorial, we are going to show you how to use Python to test the TCP connection to remote hosts.

• Ubuntu 20
• Ubuntu 19
• Ubuntu 18
• Python 3.8.5

Equipment list

The following section presents the list of equipment used to create this tutorial.

As an Amazon Associate, I earn from qualifying purchases.

Tutorial Python - Test the TCP port connectivity

Test the connectivity to a TCP port using Python.

Copy to Clipboard

Here is the command output.

Copy to Clipboard

Congratulations! You are able to test the TCP port connectivity using Python.

Tutorial Python - Test the TCP port connectivity using a script

Create a text file containing the IP list or hostnames.

Copy to Clipboard

Create a text file containing the desired TCP ports.

Copy to Clipboard

Test the connectivity to the TCP ports using a Python script.

Copy to Clipboard

Here is the command output.

Copy to Clipboard

Congratulations! You are able to test the TCP port connectivity using a Python script.