![本機 Windows CLI 工具可顯示每個 IP 位址的網路使用率](https://rvso.com/image/1606670/%E6%9C%AC%E6%A9%9F%20Windows%20CLI%20%E5%B7%A5%E5%85%B7%E5%8F%AF%E9%A1%AF%E7%A4%BA%E6%AF%8F%E5%80%8B%20IP%20%E4%BD%8D%E5%9D%80%E7%9A%84%E7%B6%B2%E8%B7%AF%E4%BD%BF%E7%94%A8%E7%8E%87.png)
在 Windows 上:尋找命令列方式來提取正在消耗的瞬時網路吞吐量(出口和入口)。資訊必須按 IP 位址分組。
它類似於 Windows 的資源監視器 -> 網路 -> 網路活動
背景:我們有 20 台 Windows 伺服器,我們希望透過在一段時間內獲取瞬時樣本來了解 (1) 它向網站添加了多少網路負載,以及 (2) 它與哪些系統通訊/從哪些系統通訊月。我無權存取路由器資料(例如,沒有人知道誰支援該路由器)。我知道 netsh trace 可能是一種選擇,但分析此類追蹤有點超出了我的範圍。
答案1
我在硬碟上發現了一個批次文件,也許可以幫助您,抱歉,我不記得從哪裡得到它?但無論如何,請嘗試一下:只需複製並貼上下面的程式碼並將其另存為列表_連接.bat並透過雙擊執行
@echo off
Title List connections
Mode 90,42 & Color 0A
setlocal enabledelayedexpansion
Set "Log=%~dpn0.txt"
If exist "%Log%" Del "%Log%"
::Used to convert PID to process names.
for /f "tokens=1 delims=" %%A in ('tasklist') do call :PID %%A
echo [Program:PID] LocalIP:Port RemoteIP:Port
(echo [Program:PID] LocalIP:Port RemoteIP:Port & echo;)>"%Log%"
echo.
for /f "tokens=1-27 delims=: " %%A in ('netstat -ano') do call :netstat %%A %%B %%C %%D %%E %%F %%G %%H %%I %%J %%K %%L %%M %%N %%O %%P %%Q %%R %%S %%T %%U
start "log" "%Log%"
pause>nul
exit /b
:PID
set pid_%2=%1
exit /b
:netstat
set type=%1
set srcIP=%2
set srcPort=%3
set dstIP=%4
set dstPort=%5
set state=%6
set pid=%7
set name=!pid_%pid%!
::Filter local connections away.
if "%state%"=="" exit /b
if not "%type%"=="TCP" exit /b
if "%srcIP%"=="Local" exit /b
if "%dstIP%"=="*" exit /b
if "%srcIP%"=="%dstIP%" exit /b
if "%pid%"=="" exit /b
if "%dstPort%"=="[" (
set state=LISTENING
set srcPort=%dstIP%
set pid=%9
)
if "%dstPort%"=="[" set name=!pid_%pid%!
if "%name%"=="" set name=Unknown
::Formatting \tabs
set srcPortTab= %srcPort%
set namePidTab=[%name%:%pid%]
set srcIpPortTab=%srcIP%:%srcPort%
set dstIpPortTab=%dstIP%:%dstPort%
set stateTab=%state%
set namePidTab=%namePidTab:~0,20%
set srcIpPortTab=%srcIpPortTab:~0,21%
set dstIpPortTab=%dstIpPortTab:~0,21%
set stateTab=%stateTab:~0,12%
set srcPortTab=%srcPortTab:~-5%
if not "%state%"=="LISTENING" echo.%namePidTab% %srcIPPortTab% %dstIPPortTab% %stateTab%
if "%state%"=="LISTENING" echo.%namePidTab% Listening on: %srcPortTab%
(
if not "%state%"=="LISTENING" echo.%namePidTab% %srcIPPortTab% %dstIPPortTab% %stateTab%
if "%state%"=="LISTENING" echo.%namePidTab% Listening on: %srcPortTab%
)>>"%Log%"
exit /b