PowerShell实时网速监控

粘贴到powershell控制台回车即可

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
<#
实时网速监控.ps1
#>
$adapter = Get-NetAdapter | Where-Object {
$_.Status -eq 'Up' -and $_.Name -notlike 'vEthernet*'
} | Select-Object -First 1

if (-not $adapter) {
Write-Host "未找到可用物理网卡"
pause
return
}
$name = $adapter.Name
$initStat = Get-NetAdapterStatistics -Name $name
$initRx = $initStat.ReceivedBytes
$initTx = $initStat.SentBytes

while ($true) {
$a = Get-NetAdapterStatistics -Name $name
Start-Sleep -Milliseconds 1000
$b = Get-NetAdapterStatistics -Name $name

#瞬时速率
$downMB = ($b.ReceivedBytes - $a.ReceivedBytes) / 1MB
$upMB = ($b.SentBytes - $a.SentBytes) / 1MB
$downMbps = $downMB * 8
$upMbps = $upMB * 8

#累计流量
$totalDownGB = ($b.ReceivedBytes - $initRx) / 1GB
$totalUpGB = ($b.SentBytes - $initTx) / 1GB

Clear-Host
Write-Host "==== 实时网速监控 网卡:$name (Ctrl+C退出) ====`n"
Write-Host "瞬时下载:$($downMB.ToString('N2')) MB/s ($($downMbps.ToString('N2')) Mbps)"
Write-Host "瞬时上传:$($upMB.ToString('N2')) MB/s ($($upMbps.ToString('N2')) Mbps)`n"
Write-Host "累计下载:$($totalDownGB.ToString('N2')) GB"
Write-Host "累计上传:$($totalUpGB.ToString('N2')) GB"
}
打赏
  • 版权声明: 本博客所有文章除特别声明外,著作权归作者所有。转载请注明出处!
  • Copyrights © 2018-2026 Outsrkem
  • 访问人数: | 浏览次数:

      请我喝杯咖啡吧~

      支付宝
      微信