Walker News

Fine tune Windows Netstat To Display Network Program And Connection In Same Line

The Windows netstat command can tell you the association of network connection and executable file, i.e. which application (program) is using the network connection port.

To get this information, you need to run this command netstat -anqb in an elevated Command Prompt window (the -b option requires elevated privilege).

Obviously, it gives what we want, but the output format is not easy to read or filter. So, let’s fine tune its output with GNU awk and grep for Windows.

Now, install that two GNU programs, then copy and paste these 3 lines to elevated Command Prompt window and press ENTER to run:
netstat -anqb |^
awk "{if ($1 ~/TCP|UDP/)printf \"\n%s\", $0;else printf \" %s\",$0}" |^

The netstat output should look better now, similar to this one:

Using GNU awk and grep program to fine tune Windows netstat command output.

NOTE: If you want to save that 3 lines in batch file (e.g. ListConn.cmd script file), you need to change each of the % character to %%, i.e.:
netstat -anqb |^
awk "{if ($1 ~/TCP|UDP/)printf \"\n%%s\", $0;else printf \" %%s\",$0}" |^

To explore Windows netstat command option, execute this command netstat /?.

Custom Search

2016  •  Privacy Policy