while ($true) {
Clear-Host
Write-Host "=== TCP Connection Status (Windows) ===" -ForegroundColor Green
Write-Host "Refresh every 5 seconds..." -ForegroundColor Yellow
# 获取所有 TCP 连接状态
$connections = Get-NetTCPConnection | Select-Object State
# 统计各状态数量
$states = $connections | Group-Object State | Sort-Object Count -Descending
# 输出状态统计
Write-Host "Connection States:" -ForegroundColor Cyan
foreach ($item in $states) {
Write-Host "$($item.Name) : $($item.Count)" -ForegroundColor White
}
# 获取已占用端口数
$usedPorts = Get-NetTCPConnection | Select-Object -ExpandProperty LocalPort | Sort-Object -Unique | Measure-Object | Select-Object -ExpandProperty Count
# 获取临时端口范围(默认值,需根据实际配置调整)
# Windows 默认临时端口范围:1024-65535(可通过注册表或 netsh 查看)
$tempStart = 1024
$tempEnd = 65535
$totalPorts = $tempEnd - $tempStart + 1
$availablePorts = $totalPorts - $usedPorts
# 输出端口统计
Write-Host "-----------------------------------" -ForegroundColor Gray
Write-Host "Temp Port Range: $tempStart -> $tempEnd" -ForegroundColor Yellow
Write-Host "Total Temp Ports: $totalPorts" -ForegroundColor Cyan
Write-Host "Used Ports: $usedPorts" -ForegroundColor Red
Write-Host "Available Ports: $availablePorts" -ForegroundColor Green
Start-Sleep -Seconds 5
}
查看tcp消耗端口情况
最新推荐文章于 2025-11-21 13:22:22 发布

1575

被折叠的 条评论
为什么被折叠?



