, , Windows script, 10 . / , CSV .
@ECHO off
SETLOCAL ENABLEDELAYEDEXPANSION
set TAB=
echo Timestamp%TAB%Down bytes%TAB%Up bytes%TAB%Down speed%TAB%Up speed
:: Store console command result
:looptask
SET count=1
FOR /F "tokens=* USEBACKQ" %%F IN (`netstat -e`) DO (
SET string!count!=%%F
SET /a count=!count!+1
)
:: Bytes transfered line is string3
:: Get rid of the whitespaces
:loopreplace
if defined string3 (
set "new=!string3: = !"
if "!new!" neq "!string3!" (
set "string3=!new!"
goto :loopreplace
)
)
if defined string3 if "!string3:~0,1!" equ " " set "string3=!string3:~1!"
if defined string3 if "!string3:~-1!" equ " " set "string3=!string3:~0,-1!"
:: Extracting bytes downloaded and uploaded
set line=%string3:~6%
FOR /F "tokens=1,2 delims= " %%A IN ("%line%") DO (
set dbytes=%%~A
set ubytes=%%~B
)
:: Midnight epoch
for /F "usebackq tokens=1,2 delims==" %%i in (`wmic os get LocalDateTime /VALUE 2^>NUL`) do if '.%%i.'=='.LocalDateTime.' set ldt=%%j
set time=%ldt:~8,2%:%ldt:~10,2%:%ldt:~12,2%
FOR /F "tokens=* delims=0" %%A IN ("%ldt:~8,2%") DO SET /A hs=%%A+0
FOR /F "tokens=* delims=0" %%A IN ("%ldt:~10,2%") DO SET /A min=%%A+0
FOR /F "tokens=* delims=0" %%A IN ("%ldt:~12,2%") DO SET /A sec=%%A+0
set /a epoch=%hs%*3600+%min%*60+%sec%
:: Calc speeds
if not defined LOOPCOMPLETE (
echo %time%%TAB%%dbytes%%TAB%%ubytes%%TAB%0.00 KB/s%TAB%0.00 KB/s
goto :skip
)
:: Read .CSV file last line values
for /f %%i in ('find /v /c "" ^< bwlog.csv') do set /a lines=%%i
set /a lastLine=%lines% - 1
SET count=1
FOR /F "tokens=* USEBACKQ" %%F IN (`more /e +%lastLine% bwlog.csv`) DO (
SET string!count!=%%F
SET /a count=!count!+1
)
FOR /F "tokens=1,2,3 delims=," %%A IN ("%string1%") DO (
set lasttime=%%~A
set lastdown=%%~B
set lastup=%%~C
)
if %epoch% == %lasttime% (
goto :skip
)
set /a dspeed=(dbytes-lastdown)/(epoch-lasttime)/10
set ddec=%dspeed:~-2%
set /a dspeed=(dbytes-lastdown)/(epoch-lasttime)/1000
set /a uspeed=(ubytes-lastup)/(epoch-lasttime)/10
set udec=%dspeed:~-2%
set /a uspeed=(ubytes-lastup)/(epoch-lasttime)/1000
echo %time%%TAB%%dbytes%%TAB%%ubytes%%TAB%%dspeed%.%ddec% KB/s%TAB%%uspeed%.%udec% KB/s
:skip
:: Append the .CSV file
echo %epoch%,%dbytes%,%ubytes% >> "bwlog.csv"
:: Do every 10 seconds
set LOOPCOMPLETE=1
timeout /t 10 /nobreak >nul
goto :looptask
ENDLOCAL
PS: Windows: 4GBytes .
XAMPP:
script Windows, , . , script .
Apache/PHP XAMPP Windows script . :
"C:\xampp\php\php.exe -f C:\xampp\htdocs\bwlog.php"
bwlog.php script @phep answer Windows netstat -e. script , :
<?php
$netstat=shell_exec("netstat -e");
$line=substr($netstat,strpos($netstat,"Bytes"));
$line=substr($line,0,strpos($line,"\n"));
$bytes=preg_replace('/\s+/', ' ',$line);
$bytes=substr($bytes,$start=strpos($bytes,' ')+1,strrpos($bytes,' ')-$start);
file_put_contents('C:\xampp\htdocs\bwlog.csv',PHP_EOL.time().', '.$bytes,FILE_APPEND);
?>
.csv , ( ), 2 (/).
. , .