首页  编辑  

监控系统网络速度iftop

Tags: /计算机文档/脚本,批处理/   Date Created:
类似Linux下的iftop,可以查看系统当前的网络速度:
$Host.UI.RawUI.WindowTitle = 'iftop'
$adapter = Get-NetAdapter | Where-Object { $_.Status -eq "Up" -and $_.HardwareInterface -eq $true }
if ($adapter.Count -eq 0) {
	echo "没有活动网卡"
	exit
}
$prev = @{}
$adapter | ForEach-Object { $prev[$_.Name] = $_ | Get-NetAdapterStatistics }
while ($true) {
	sleep 1
	foreach ($adpt in $adapter) {
			$cur = $adpt | Get-NetAdapterStatistics
			$old = $prev[$adpt.Name]
			$rx = ($cur.ReceivedBytes - $old.ReceivedBytes) / 1024
			$tx = ($cur.SentBytes - $old.SentBytes) / 1024
			Write-Host -NoNewline "`r".PadRight(80)
			Write-Host -NoNewline ("`r{0}: ↓ {1} 字节 - {2:N2} KB/s ↑ {3} 字节 - {4:N2} KB/s" -f $adpt.Name, $cur.ReceivedBytes, $rx, $cur.SentBytes, $tx)
			$prev[$adpt.Name] = $cur
	}
}

Doskey定义:
doskey iftop=powershell -encodedCommand JABIAG8AcwB0AC4AVQBJAC4AUgBhAHcAVQBJAC4AVwBpAG4AZABvAHcAVABpAHQAbABlACAAPQAgACcAaQBmAHQAbwBwACcACgAkAGEAZABhAHAAdABlAHIAIAA9ACAARwBlAHQALQBOAGUAdABBAGQAYQBwAHQAZQByACAAfAAgAFcAaABlAHIAZQAtAE8AYgBqAGUAYwB0ACAAewAgACQAXwAuAFMAdABhAHQAdQBzACAALQBlAHEAIAAiAFUAcAAiACAALQBhAG4AZAAgACQAXwAuAEgAYQByAGQAdwBhAHIAZQBJAG4AdABlAHIAZgBhAGMAZQAgAC0AZQBxACAAJAB0AHIAdQBlACAAfQAKAGkAZgAgACgAJABhAGQAYQBwAHQAZQByAC4AQwBvAHUAbgB0ACAALQBlAHEAIAAwACkAIAB7AAoACQBlAGMAaABvACAAIgChbAlnO22oUlF/YVMiAAoACQBlAHgAaQB0AAoAfQAKACQAcAByAGU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