|
@echo off
:init
setlocal DisableDelayedExpansion
set "batchPath=%~0"
for %%k in (%0) do set batchName=%%~nk
set "vbsGetPrivileges=%temp%\MYSQL_INIT_getPriv_%batchName%.vbs"
setlocal EnableDelayedExpansion
:checkPrivileges
NET FILE 1>NUL 2>NUL
if '%errorlevel%' == '0' ( goto gotPrivileges ) else ( goto getPrivileges )
:getPrivileges
if '%1'=='ELEV' (echo ELEV & shift /1 & goto gotPrivileges)
ECHO Set UAC = CreateObject^("Shell.Application"^) > "%vbsGetPrivileges%"
ECHO args = "ELEV " >> "%vbsGetPrivileges%"
ECHO For Each strArg in WScript.Arguments >> "%vbsGetPrivileges%"
ECHO args = args ^& strArg ^& " " >> "%vbsGetPrivileges%"
ECHO Next >> "%vbsGetPrivileges%"
ECHO UAC.ShellExecute "!batchPath!", args, "", "runas", 1 >> "%vbsGetPrivileges%"
"%SystemRoot%\System32\WScript.exe" "%vbsGetPrivileges%" %*
exit /B
:gotPrivileges
setlocal & pushd .
cd /d %~dp0
if '%1'=='ELEV' (del "%vbsGetPrivileges%" 1>nul 2>nul & shift /1)
::==================================================================================
::判断是否有相同的MAC,如果相同就直接运行Serf命令,不同就手动选择
del mac2.ini >nul 2>nul
if not exist mac.ini goto :startn
findstr "物理地址" mac.ini ||del mac.ini>nul &&goto :startn
findstr /c:"物理地址" mac.ini >mac2.ini
for /f "tokens=2 delims=:" %%i in (mac2.ini) do set mac3=%%i
ipconfig /all | findstr /c:"%mac3:~1, 17%">nul 2>nul
if errorlevel 1 (echo.不存在 "%mac3:~1, 17%" &&goto :startn)
cls
if errorlevel 0 (echo.已存在 "%mac3:~1, 17%" &&goto :checkip)
:checkip
netsh interface ipv4 set global dhcpmediasense=disabled >nul
nbtstat -n | findstr /c:"192.168.2.1" >nul 2>nul
if errorlevel 1 (echo.不存在 "192.168.2.1" &&goto :startn)
if errorlevel 0 (echo.已存在 "192.168.2.1" &&echo.=======================================&&goto :waitinput)
::=============================================================================
:waitinput
@echo off&if not "%1"=="" call%*&exit||{zb-2024-06-05}
::纯批实现等待指定输入
:begin
call:timeout 5 :tsk1 0 :tsk2
:tsk1
echo\&echo 【默认计划】
goto :Serf
:tsk2
echo\&echo 【自定义计划】
goto :reset
:: /*----------------- timeout --------------------
:timeout [num] [:label1] [STR] [:LABEL2]
setlocal&del/a/q %tmp%\' 2>nul||(echo 未知错误!&pause&exit)
start/b/REALTIME %~s0 :timeout_1 %1 %2 %3 %4
:timeout_2
set "v="
set/p v=
if %v%.==%3. title %ComSpec%&cd.>%tmp%\'&endlocal&goto%4
if exist %tmp%\' exit ::没有输入,退出timeout
goto:timeout_2
:timeout_1 [num] [:label1] [STR] [:LABEL2]
for /l %%a in (%1 -1 0)do (
title 【倒计时:%%a秒内输入:"%3" 重置网络】
if exist %tmp%\' title %ComSpec%&exit
ping/n 2 127.1 >nul)
title %ComSpec%&cd.>%tmp%\'&goto%2
:: /*------------------ timeout -------------------*/
::====================================================================================
:startn
setlocal EnableDelayedExpansion
del abc.txt>nul 2>nul
::获取网卡列表
for /f "tokens=2 delims==" %%i in ('wmic nic where "not NetConnectionID is null" get Name^,NetConnectionID^,DeviceID /value') do (echo.%%i>>abc.txt)
::获取abc.txt行数
type abc.txt | find /c /v "">m.ini
set /p m=<m.ini
::选择第n行, 设置变量为a1=?, a2=?, a3=?, an=????
set n=1
set /a n-=1
if "%n%"=="0" (set "skip=") else (set "skip=skip=%n%")
for /f "%skip% tokens=* delims=" %%i in (abc.txt) do (
set /a nn=!n!+1
set "a=a!nn!=%%i" &&call :a
)
echo ===================================
echo.%a1%
echo.%a2%
echo.%a3%
echo............
echo ===================================
cls
goto :startMe
:a
echo.!a!&&set !a!
cls
set /a n=!n!+1
goto :eof
:startMe
::=====================================================================================
title 快速设置网卡IP
echo.
echo. 快速设置网卡IP:192.168.2.1
echo ===================================================================================
::网卡类别排序:
set y=1
for /l %%i in (3, 3, %m%) do (
REM echo.
REM echo !y! !a%%i!
set "z!y!=!a%%i!"
set /a y=!y!+1
)
set /a y-=1
::网卡详细名称:
set q=1
for /l %%i in (2, 3, %m%) do (
echo.
echo !q! !a%%i!
set "c!q!=!a%%i!"
set /a q=!q!+1
)
rem set /a q-=1
echo ====================================================================================
echo.
set /a maxnum=%m%/3
set /p choice=选择网卡:
echo.
set choiceNetID=!z%choice%!
set choiceNNAME=!c%choice%!
echo.
if "%choice%" == "0" (goto :reset)
if %choice% leq %maxnum% (goto :aaa)
if %choice% gtr %maxnum% (cls&&echo.&&echo.序号输入错误, 请重新输入&&timeout 2&&goto :startn)
::重置网络
:reset
cls
set num=1
set no=1
for /f "tokens=2 delims==" %%i in ('wmic nic where "not NetConnectionID is null" get NetConnectionID^,DeviceID /value') do (
set /a mo=!num!"%%"2
if "!mo!" == "0" (
set NetID=%%i
set "Obj[!no!].NetID=%%i"
rem echo !no! 、 网卡名称:!NetID!
echo.正在重置 !NetID:~0,-2!
del mac.ini>nul 2>nul
del ipmac.ini>nul 2>nul
@echo 自动获取ip地址>nul
netsh int ip set add name="!NetID:~0,-2!" source=dhcp>nul
@echo 自动获取DNS服务器>nul
netsh int ip set dns name="!NetID:~0,-2!" source=dhcp>nul
@echo 正在设置DNS为自动获取>nul
netsh interface ip set dns name="!NetID:~0,-2!" source=dhcp>nul
set /a no+=1
)
set /a num+=1
)
set /a no-=1
echo.
echo.网络重置完成!
goto :startn
echo ==================================================================================
:aaa
echo.当前网卡: !choice! !c%choice%!
echo.
choice /t 1 /d y /n>nul
netsh interface ip set address "%choiceNetID%" static 192.168.2.1 255.255.255.0
goto :findmac
echo ----------------------------------------分割线-------------------------------------------------
echo ========================================
echo 1、启用
echo 2、禁用
echo 3、重启
echo 4、设置IP:192.168.2.1
echo.
set /p choice_type=请选择操作:
echo ========================================
if "%choice_type%" == "1" (
echo 正在启用网卡:!choiceNetID!
netsh interface set interface name="%choiceNetID%" admin=ENABLED
goto :startMe
)
if "%choice_type%" == "2" (
echo 正在禁用网卡:!choiceNetID!
netsh interface set interface name="%choiceNetID%" admin=DISABLED
goto :startMe
)
if "%choice_type%" == "3" (
echo 正在重启网卡:!choiceNetID!
netsh interface set interface name="%choiceNetID%" admin=DISABLED
netsh interface set interface name="%choiceNetID%" admin=ENABLED
goto :startMe
)
if "%choice_type%" == "4" (
netsh interface ip set address "%choiceNetID%" static 192.168.2.1 255.255.255.0
goto :findmac
)
goto :aaa
echo ----------------------------------------分割线-------------------------------------------------
:findmac
ipconfig /all>ipmac.ini
::查找网卡名称下4行
For /f "tokens=1* delims=:" %%i in ('Type ipmac.ini^|Findstr /n /c:"%choiceNetID%:"') do (Set n=&Set /a n=%%i+4 && Echo %%j>mac.ini)
For /f "tokens=1* delims=:" %%a in ('Type ipmac.ini^|Findstr /n /c:"."') do (If %%a==!n! Echo %%b>>mac.ini &&set /a n=!n!+1 )
rem For /f "tokens=1* delims=:" %%a in ('Type ipmac.ini^|Findstr /n /c:"."') do (If %%a==!n! Echo %%b>>mac.ini)
:Serf
del ipmac.ini >nul 2>nul
del mac2.ini >nul 2>nul
title 【Iperf3-网络对传】
cls
echo.!c%choice%!
iperf3.exe -s
|
|