October 2017
Intermediate to advanced
440 pages
11h 47m
English
The netstat command produces tab-delimited, fixed-width tables. The following example converts the active connections that list active TCP connections as well as listening TCP and UDP ports to an object.
A snippet of the output the example is intended to parse is shown in the following code:
PS> netstat -anoActive Connections Proto Local Address Foreign Address State PID TCP 0.0.0.0:135 0.0.0.0:0 LISTENING 124 TCP 0.0.0.0:445 0.0.0.0:0 LISTENING 4 TCP 0.0.0.0:5357 0.0.0.0:0 LISTENING 4
When handling text such as this, a pattern based on whitespace (or not whitespace) can be used:
^\s*\S+\s+\S+
For each column, the following expression with a named group is created:
(?<ColumnName>\S+)\s+
The trailing \s+ is omitted for the ...
Read now
Unlock full access