PowerShell是Windows原生网络监控工具,支持进程级连接查看、实时网卡速率监控、特定目标地址筛查及短期流量日志记录。
powershell 是 windows 系统原生支持的高效网络连接监控工具,无需安装第三方软件,能直接调用系统底层接口获取实时、进程级、可脚本化的网络活动数据。
查看当前活跃 TCP 连接及所属进程
这是定位“谁在联网”的最直接方式。运行以下命令可列出所有已建立的远程连接,并附带进程名和 PID:
Get-NetTCPConnection | Where-Object {$_.State -eq 'Established'} | Select-Object LocalAddress, RemoteAddress, State, @{Name='ProcessName';Expression={(Get-Process -Id $_.OwningProcess -ErrorAction SilentlyContinue).ProcessName}}, OwningProcess | Sort-Object -Property OwningProcess
常见高流量或需关注的进程包括:svchost.exe(可能承载 Windows Update、BITS)、msedge.exe(后台更新/渲染)、Teams.exe(音视频传输)、OneDrive.exe(文件同步)等。若发现陌生进程持续连接外网,可进一步用 Get-Process -Id X 查看其路径与启动时间。
实时监控网卡收发速率(秒级刷新)
适用于快速判断带宽是否被占满。先确认网卡名称:
Get-NetAdapter | Where-Object {$_.Status -eq 'Up'} | Select-Object Name, LinkSpeed
再执行循环采样(示例中网卡名为 Ethernet):
while ($true) { Clear-Host $rx = (Get-Counter "\Network Interface\Ethernet\Bytes Received/sec").CounterSamples.CookedValue $tx = (Get-Counter "\Network Interface\Ethernet\Bytes Sent/sec").CounterSamples.CookedValue Write-Host "↓ $("{0:N0}" -f $rx) B/s | ↑ $("{0:N0}" -f $tx) B/s" -ForegroundColor Green Start-Sleep -Seconds 2 }
数值单位为字节/秒;除以 1024² 可换算为 MB/s。按 Ctrl + C 停止刷新。
筛查特定目标地址的连接行为
当需重点关注某类访问(如内部系统、敏感域名、可疑 IP),可用过滤脚本快速扫描:
- 检查是否连接到指定 IP 或域名(如 192.168.10.5 或 api.example.com):
Get-NetTCPConnection | Where-Object {$_.RemoteAddress -eq '192.168.10.5' -or $_.RemoteAddress -like '*example.com*'} | Select-Object LocalAddress, LocalPort, RemoteAddress, RemotePort, State, OwningProcess - 结合进程信息输出更完整上下文:
... | ForEach-Object { $proc = Get-Process -Id $_.OwningProcess -ErrorAction SilentlyContinue; [PSCustomObject]@{ Process = $proc?.ProcessName; PID = $_.OwningProcess; Remote = "$($_.RemoteAddress):$($_.RemotePort)" } }
记录短期流量日志用于回溯分析
若需保留一段时间内的趋势数据(例如排查每日早高峰异常),可导出为 CSV 文件:
$logPath = "$env:USERPROFILE\Desktop\network_usage_$(Get-Date -Format 'yyyyMMdd_HHmm').csv" 1..30 | ForEach-Object { $rx = (Get-Counter "\Network Interface\Ethernet\Bytes Received/sec").CounterSamples.CookedValue $tx = (Get-Counter "\Network Interface\Ethernet\Bytes Sent/sec").CounterSamples.CookedValue [PSCustomObject]@{ TimeStamp = Get-Date -Format 'HH:mm:ss'; Rx_Bps = [int]$rx; Tx_Bps = [int]$tx } } | Export-Csv -Path $logPath -NoTypeInformation
该脚本每秒采样一次,共 30 秒,保存至桌面,文件名含时间戳,便于归档对比。


















