简易WLAN上传下载查看器by批处理
测试环境:windows10
使用方法:
1.新建记事本另存,文件类型所有文件,编码ansi,名称上传下载查看器.bat。
2.双击运行。
3.有问题反馈。
原理:
使用Get-NetAdapterStatistics获取WLAN时间段内的接收和发送字节计算获取速度。
@echo off
setlocal enabledelayedexpansion
title 上传下载查看器by phenix,邮箱279682817@qq.com
call :main
:main
set startDate=
set duration=0
set startRecValue=0
set startSenValue=0
set endRecValue=0
set endSenValue=0
set showMsg=
for /f "tokens=*" %%a in ('powershell -command "& {date}"') do (
set startDate='%%a'
)
rem echo !startDate!
for /f "skip=3 tokens=1,2,3,4* delims= " %%b in ('start /wait /b powershell -command "& {Get-NetAdapterStatistics|format-table -property name,receivedbytes,sentbytes}"') do (
if "%%b" equ "WLAN" (
set startRecValue=%%c
set startSenValue=%%d
)
)
rem echo !startRecValue!
rem echo !startSenValue!
for /f "tokens=1,2* delims=:" %%i in ('powershell -command "& {$d1=[datetime]!startDate!;$d2=date;$d2-$d1|format-list -property seconds}"') do (
set duration=%%j
if "!duration!" equ "0" (
set duration=1
)
)
rem echo !duration!
for /f "skip=3 tokens=1,2,3,4* delims= " %%f in ('start /wait /b powershell -command "& {Get-NetAdapterStatistics|format-table -property name,receivedbytes,sentbytes}"') do (
if "%%f" equ "WLAN" (
set endRecValue=%%g
set endSenValue=%%h
)
)
rem echo !endRecValue!
rem echo !endSenValue!
for /f "tokens=*" %%k in ('powershell -command "& {$recValue=[bigint]!endRecValue!-[bigint]!startRecValue!;([bigint]($recValue/[bigint]!duration!)).toString('n0')|foreach-object {$_}}"') do (
set showMsg=下载速度:%%k字节/秒,
)
for /f "tokens=*" %%l in ('powershell -command "& {$senValue=[bigint]!endSenValue!-[bigint]!startSenValue!;([bigint]($senValue/[bigint]!duration!)).toString('n0')|foreach-object {$_}}"') do (
set showMsg=!showMsg!上传速度:%%l字节/秒,
)
echo !showMsg!
powershell -command "& {start-sleep -seconds 1}"
cls
goto :main