Using netstat to get list of open ports

The easy way to check what are the current open ports, on a windows base computer, is by opening the command line tool, by typing cmd in the run command, hitting enter and wait for the black command line window to appear.

Netstat open ports
Using netstat to get list of open ports

Here are some steps to open the run command you can use some methods:

  1. Press the windows button, aka start, and in the line, where you can write, type cmd and press enter ( the line is where you can search programs and files).
  2. Using the keyboard you can press the windows key together with the R key/button, this will open the run command, type in cmd and press enter, where you see the Open text.

Running netstats forĀ open ports testing:

When the command line window is open you can type in netstat -an and press enter. This will output a list of current open port. It include the protocol type – TCP/UDP. The IP address that the port is open on. The IP address that this port is connected to and the port number that it use.

The command netstat -an means:

  • netstat – this is the command we use.
  • a – tell netstat to bring all the current connection and listen ports.
  • n – tell it to show the IP addresses and the port number in numeric form.

The port number that it use is the open ports on the current computer, so here is some more explanation about the netstat output command:

  • Proto:
    The protocol that the current connection is use, re TCP, UDP.
  • Local Address:
    The Local address that it use, re your IP address or localhost, 127.0.0.1, 0.0.0.0 the colon (punctuation) aka (:) is a splitter that split the IP from the Port, so what you see after the colon (punctuation) is the current open port number.
  • Foreign Address:
    The target address, remote computer, that this port is connected to, also in here the colon (punctuation) represent a letter to the address and the port number.
  • State:
    There are some state the you can see in the command line, here are some that are more commons:
    LISTENING – The port is open and wait for connections, this is a typical behavior for services wait for connection over the network.
    ESTABLISHED – This state indicated that there is currently a connection between the local IP, yours, to a target server.

Looking on the netstat output results:

Netstat command line a cool tool that can give you information about open port in your local computer. If you are using a lot of software. That running on your computer and connected over the network.

Here is a method to output the netstat output into a log (or text) file. Using this will popup a list of open ports into a text file. This list might be too long to see it all on the command line. But will be perfectly view using a text editor.

I am recommended using a text viewer like notepad++ that can be freely download from the link. This viewer will let you see it in an organize way.

How to output the command into a text file?

Here is the command to use for pointing the netstat command output into a file:
netstat -an > c:\out.txt

Please note the ‘>’ sign that make the output available. By the way, this will work with most of the command line command for outpointing the command output into a file.

Once done. The result data saved into a file called out.txt. The file will be on the root folder of drive C (c:\).
You can open explorer, navigate to the root folder to open and view the file even with your newly installed notepad++.

This method is a good to know. In here we use it to get the current open ports on your system. As mention above it is also works on other command line tools.

Another good to know tip is the -? parameter, why? because using it will show you the parameters that netstat command line can use.

netstat -? – Will show you the netstat command line help screen. And yes, this -? will also works with other command line tools.

Leave a Comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.