查看tcp消耗端口情况

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
}
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

万物琴弦光锥之外

给个0.1,恭喜老板发财

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值