powershell 查看程序的tcp网络连接

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/shrekz/article/details/38585417
在运维工作中,经常查看某个业务的网络连接状况,在这里借用netstat来实现查找连接,用hash特性避免重复。
$add=@{}
while(1){
ps|?{$_.path  -match 'E:\\games\\梦幻XX}|%{
$id=$_.id
netstat -ano |
    ForEach-Object {
       $i = $_ | Select-Object -Property Protocol , Source , Destination , Mode ,pid
       $null, $i.Protocol, $i.Source, $i.Destination, $i.Mode, $i.pid=  ($_ -split '\s{2,}')
       $i
    }|?{$_.pid -eq $id}|%{
    try{
       $add+=@{$_.Destination=$_.Source}
        $_}
    catch{}
    }}
    sleep 1
}
$add

猜你喜欢

转载自blog.csdn.net/shrekz/article/details/38585417