Powershell

This will perform a basic netstat.exe command and “objectize” its output. This version only handles the TCP stuff because I ran out of time. This needs perhaps a switch statement and a second regex to do the rest justice. Also, I’d like to see in a v2 the capability to tie process names in via the PID column and output the real process name and file info and so on.  If you want to hack on it, just click on the PoshCode link below the script listing and update it in place.

Here is an example showing the obvious benefits of turning screen output into an object:

image

: http://halr9000.com/article/599

2008-08-27 13:37:50

the System.NET class give you objects directly, to bad it does not list the sid

$gp = [Net.NetworkInformation.IPGlobalProperties]::GetIPGlobalProperties()
$gp
$gp.GetActiveTcpConnections()
$gp.GetActiveTcpConnections()[0].localendpoint.port

more info
http://thepowershellguy.com/blogs/posh/archive/2007/03/02/hey-powershell-guy-how-can-i-change-the-first-two-octets-of-an-ip-address.aspx

did not look into getting a PID yet.

Enjoy,
Greetings /\/\o\/\/

2008-08-27 13:47:50

Oops,

http://www.codeguru.com/forum/showthread.php?p=1748321

not even a simple P/Invoke seems to do, undocumented interfaces, you’re right let’s just wrap-up netstat for this hehe .
Still net NET class is handy without it

$gp.GetIcmpV4Statistics()
$gp.GetActiveTcpListeners()
$gp.GetActiveUdpListeners()

Greetings /\/\o\/\/

2008-08-27 20:50:35

Ask and you shall receive…

http://poshcode.org/558

~Glenn

2009-11-24 07:53:58

[...] have any cmdlets similar to netstat. The Grand Poobah of PowerShell (@halr9000 on twitter) has a PowerShell script to “objectize” netstat, but that crosses in to scriptland so we will steer [...]

2010-01-14 18:17:26

[...] have any cmdlets similar to netstat. The Grand Poobah of PowerShell (@halr9000 on twitter) has a PowerShell script to “objectize” netstat, but that crosses in to scriptland so we will steer [...]

2010-01-14 18:29:04

[...] have any cmdlets similar to netstat. The Grand Poobah of PowerShell (@halr9000 on twitter) has a PowerShell script to “objectize” netstat, but that crosses in to scriptland so we will steer [...]

  • Microblog

  • Recent Posts

  • Recent Comments

  • meta

  • PowerShell Blogroll