利用wolcmd.exe批处理执行远程唤醒

代码如下:

@echo off
cls

:check
if exist wolcmd.exe goto targetmac
echo 缺少wolcmd.exe
echo.
goto end

:targetmac
cls
echo --------------------------------------------------------
echo 目标主机PC-01地址:40235678AEFF 192.168.1.23
echo 目标主机PC-02地址:40235678AE68 192.168.1.24
echo 目标主机PC-03地址:40235678AE7A 192.168.1.25
echo 目标主机PC-04地址:40235678AE7A 192.168.1.26
echo 目标主机PC-05地址:40235678AE3E 192.168.1.27
echo 目标主机PC-06地址:40235678AE79 192.168.1.28
echo 目标主机PC-07地址:40235678AE8F 192.168.1.29
echo 目标主机PC-08地址:40235678AE8E 192.168.1.30
echo 目标主机PC-09地址:40235678AE48 192.168.1.31
echo 目标主机PC-10地址:40235678AE24 192.168.1.32
echo 目标主机PC-11地址:40235678AEF8 192.168.1.33
echo 目标主机PC-12地址:40235678AE27 192.168.1.34
echo 目标主机PC-13地址:40235678AE78 192.168.1.35
echo 目标主机PC-14地址:40235678AE90 192.168.1.36
echo 目标主机PC-15地址:40235678AE2C 192.168.1.37
echo 目标主机PC-16地址:40235678AEE3 192.168.1.38
echo 目标主机PC-17地址:40235678AED6 192.168.1.39
echo 目标主机PC-18地址:40235678AE0E 192.168.1.40
echo 目标主机PC-19地址:40235678AE52 192.168.1.41
echo 目标主机PC-20地址:40235678AEF1 192.168.1.42
echo --------------------------------------------------------
echo.
set mac=
set /p mac="输入目标主机MAC地址:"

rem 判断是否有输入
if not defined mac (echo 没有输入任何内容,按任意键返回重新输入MAC地址↑ & pause>nul & goto targetmac)

rem 获取输入的字符串长度
set str=%mac%
set num01=
:next
if not "%str%"=="" (
    set /a num01+=1
    set "str=%str:~1%"
    goto next
)

rem 判断mac字符串长度是否为12
if %num01% neq 12 (echo 你输入了%num01%个字符:“%mac%”,长度不正确! MAC地址应由12位十六进制字符(0~9,A~F)组成,按任意键返回重新输入MAC地址↑ & pause>nul & goto targetmac)

rem 判断输入的字符串是否有空格
setlocal enabledelayedexpansion
set counts=1
for /l %%i in (0,1,11) do (
	if "!mac:~%%i,1!" == " " (echo 不要输入空格:第!counts!个字符是空格,按任意键返回重新输入MAC地址↑ & pause>nul & goto targetmac)
	set /a counts+=1
)

rem 在当前文件中获取对应的IP地址
set thisfilename=%~n0
for /f "tokens=3,*" %%i in ('findstr /I %mac% "%thisfilename%.bat"') do (set thisip=%%i)
if /i {%thisip%}=={} (echo 在“%thisfilename%.bat”文件中没有查询到相关的IP地址,按任意键返回重新输入MAC地址↑ & pause>nul & goto targetmac)
echo 查询到该主机的IP地址为:%thisip%

:continue
wolcmd %mac% 192.168.1.255 255.255.255.0
echo 已发送远程开机指令。

echo.
echo 开始ping测试
ping %thisip% -t
goto end

:end
echo.
echo 5秒内自动关闭。
timeout /t 5 /nobreak
exit

你可能感兴趣的:(技术类)