cmd Displaying network connections


Displaying network connections in the Windows Command Prompt (cmd) is crucial for monitoring the status of your network, identifying active connections, and diagnosing potential issues. You can use various commands to view details about current network connections, open ports, and their respective states. Below, I’ll explain some of the most commonly used commands for displaying network connections, along with examples and expected outputs.

1. Using the netstat Command

The netstat (Network Statistics) command provides detailed information about current network connections, including protocol, local and remote addresses, port numbers, and the status of each connection.

Basic Syntax:

netstat

Example:

To view all current network connections, enter:

netstat

Output:

C:\Users\YourUsername>netstat Proto Local Address Foreign Address State TCP 192.168.1.10:49152 google.com:80 ESTABLISHED TCP 192.168.1.10:49153 example.com:443 TIME_WAIT TCP 192.168.1.10:49154 203.0.113.45:23 CLOSE_WAIT UDP 192.168.1.10:5353 *:*

Output Explanation:

  • Proto: The protocol used (TCP or UDP).
  • Local Address: The local IP address and port number of the connection.
  • Foreign Address: The remote IP address and port number of the connection.
  • State: The current state of the TCP connection (e.g., ESTABLISHED, TIME_WAIT, CLOSE_WAIT).

2. Using the netstat -a Command

The -a option shows all active connections and listening ports.

Example:

To display all active connections and listening ports, enter:

netstat -a

Output:

C:\Users\YourUsername>netstat -a Proto Local Address Foreign Address State TCP 192.168.1.10:49152 google.com:80 ESTABLISHED TCP 192.168.1.10:49153 example.com:443 TIME_WAIT TCP 192.168.1.10:49154 203.0.113.45:23 CLOSE_WAIT TCP 192.168.1.10:49155 *:80 LISTENING UDP 192.168.1.10:5353 *:*

3. Using the netstat -n Command

The -n option displays addresses and port numbers in numerical form, which can be faster since it avoids resolving hostnames.

Example:

To show connections without resolving hostnames, enter:

netstat -n

Output:

C:\Users\YourUsername>netstat -n Proto Local Address Foreign Address State TCP 192.168.1.10:49152 172.217.6.206:80 ESTABLISHED TCP 192.168.1.10:49153 203.0.113.45:443 TIME_WAIT UDP 192.168.1.10:5353 0.0.0.0:0

4. Using the netstat -o Command

The -o option displays the Process ID (PID) associated with each connection, allowing you to identify which application is using the connection.

Example:

To show connections with their associated PIDs, enter:

netstat -o

Output:

C:\Users\YourUsername>netstat -o Proto Local Address Foreign Address State PID TCP 192.168.1.10:49152 google.com:80 ESTABLISHED 1234 TCP 192.168.1.10:49153 example.com:443 TIME_WAIT 5678

5. Using the netstat -p Command

You can specify a protocol with the -p option to filter the connections. For example, to view only TCP connections, use:

Example:

netstat -p tcp

Output:

C:\Users\YourUsername>netstat -p tcp Proto Local Address Foreign Address State TCP 192.168.1.10:49152 google.com:80 ESTABLISHED

6. Using the tasklist Command

You can also use the tasklist command to see a list of running processes, which can be useful in conjunction with the netstat -o command to identify which application is using a specific port.

Example:

To view the list of currently running processes, enter:

tasklist

Output:

C:\Users\YourUsername>tasklist Image Name PID Session Name Session# Mem Usage ========================= ======== ================ =========== ============ System Idle Process 0 Services 0 28 K System 4 Services 0 376 K smss.exe 484 Services 0 224 K csrss.exe 576 Console 1 1,024 K wininit.exe 660 Services 0 544 K

Summary

Displaying network connections in the Windows Command Prompt can be accomplished using various commands, such as netstat, which provides detailed information about active connections, listening ports, and associated process IDs. By combining these commands, you can effectively monitor your network activity, identify potential issues, and troubleshoot network connectivity problems. Understanding how to use these commands is essential for network management and security.