Would you like to learn how to open a TCP port using Python? In this tutorial, we are going to show you how to use Python to configure a TCP port in listening mode on a computer running Linux.

• Ubuntu 18
• Ubuntu 19
• Ubuntu 20
• Ubuntu 22

Related tutorial – Python

On this page, we offer quick access to a list of tutorials related to Python.

Tutorial Python – Opening a TCP port

Create a Python script to open a TCP port.

Copy to Clipboard

Here is the script content.

Copy to Clipboard

Execute the Python script to open a TCP port.

Copy to Clipboard

In our example, we configured a Python script to open the TCP port 55.

On a remote computer, connect to the TCP port.

Copy to Clipboard

Optionally, use a Telnet client application.

Powershell - Open TCP Port

Here is the command output.

Copy to Clipboard

Type something to send data over the TCP connection.

Copy to Clipboard

All information received over the TCP connection will be displayed on the screen.

Copy to Clipboard

Optionally, store all data received in a text file.

Copy to Clipboard

All information received over the TCP connection will be saved on a text file named TCPLOG.

Congratulations! You are able to open a TCP port using Python.