sendMsg.cmd 代码如下:
@echo %dbg% off
cls
echo.
echo 调试状态:在命令行上执行 set dbg=on 即可显示执行回显过程
echo 关闭调试:在命令行上执行 set dbg= 即可关闭回显进入正常运行模式
echo 退出执行:在执行过程中如需终止运行,按 Q 键退出
echo 简单测试:arp -a 列出其中ip,将此ip填入 set ".IP=填入这里" 进行实验
echo.
:Redtek 2006
:: 设定被ARP操作的IP地址
:: set ".IP=192.168.0.12"
set ".IP= 192.168.0.251"
:: 设定消息接收者:为用户windows的登录名
set ".sessionName=%username%"
:: 设定存有显示消息的临时文件名
set ".saveFile=temp.txt"
:: 设定显示消息的时间:秒
set ".viewTime=2"
:: 设定显示执行下一个消息窗口指令的时间:秒
set ".DoNextCmd=5"
:: 设定消息窗口显示次数
set ".loopRunNum=20"
:: 追加方式初始化临时文件,防止意外错误
echo.>>"%.saveFile%"
:start
set /a ".loopRunNum-=1"
if %.loopRunNum%==0 goto :end
for /f "tokens=1,2" %%i in ('arp -a^|findstr /c:"%.IP%"') do ( echo %%i %%j>>"%.saveFile%" )
msg "%.sessionName%" <"%.saveFile%" /time:%.viewTime% /w
choice /T %.DoNextCmd% /C rq /d r /n>nul
if %errorlevel%==2 goto :end
goto :start
:end
:: 清除使用过的变量
:: 使用的变量前面加一个统一标置符“.”是为了注销变量时方便:)
for /f "delims==" %%i in ('set .') do set "%%i="
set "dbg="
在 “:Redtek 2006” 标签代码段可根据自己需要的值更改初始变量。
原理: 利用 Windows 系统自带的工具 MSG 消息发送系统来完成消息的显示工具。
MSG 的 /w 参数具有 “阻塞执行状态” 执行显示当前窗口的功能,执行时系统处于等待状态,直行完才退出。
MSG 的 /TIME 参数具有等待接收器确认消息的时间延迟功能,即除非用户主动结束窗口,否则消息在显示指定的n秒后结束显示。
这样就代替了以强行杀掉进程的操作试图完成关闭消息显示窗口的方法。
同时,MSG 可以将指定的消息发送到局域网内的任何一台计算机内,无论是广播还是指定接收者,都能如愿以偿的执行:)
如果使用 Ping -n ....<nul 指令以求间接达到 “延时” 的效果,则CPU将处于高负荷状态,甚至达到90%。
所以使用了 CHOICE 来达到等待延时的效果,经测试其CPU峰值约0-2%左右。
而 CHOICE 的取用户选择值的功能,可以达到按指定的键则终止代码运行,方便用户执行期间安全退出。
当执行 ARP 时,其 CPU 测试峰值约为 2-13%,对系统影响不大。
for /f "delims==" %%i in ('set .') do set "%%i=" 这条语句是为了清除使用过的变量而设置的。
代码中所用到的变量均为前面加一个 “.”,这样当我使用完它们时则一个For就可以了,不用一个一个列出来再删。
这是利用了 SET . 当此操作时,系统会显示所有以 “.” 开头的变量,一个for自然全部将其找到并“引入”,然后赋“空”值清除操作。
) 另:中文版 Windows XP 系统如果你找不到 CHOICE.EXE 文件,则这个文件与此代码一同被压缩进此贴附件内,需要的朋友方便下载:)
sendMsg.cmd code is as follows:
@echo %dbg% off
cls
echo.
echo Debug status: Execute set dbg=on on the command line to display the execution echo process
echo Turn off debugging: Execute set dbg= on the command line to turn off echo and enter normal operation mode
echo Exit execution: If you need to terminate the operation during execution, press the Q key to exit
echo Simple test: arp -a lists the IPs, fill this IP into set ".IP=fill here" for experiment
echo.
:Redtek 2006
:: Set the IP address to be ARP operated
:: set ".IP=192.168.0.12"
set ".IP= 192.168.0.251"
:: Set the message receiver: it is the login name of the user's windows
set ".sessionName=%username%"
:: Set the temporary file name for displaying messages
set ".saveFile=temp.txt"
:: Set the time to display the message: seconds
set ".viewTime=2"
:: Set the time to display the command of the next message window: seconds
set ".DoNextCmd=5"
:: Set the number of times the message window is displayed
set ".loopRunNum=20"
:: Initialize the temporary file in append mode to prevent unexpected errors
echo.>>"%.saveFile%"
:start
set /a ".loopRunNum-=1"
if %.loopRunNum%==0 goto :end
for /f "tokens=1,2" %%i in ('arp -a^|findstr /c:"%.IP%"') do ( echo %%i %%j>>"%.saveFile%" )
msg "%.sessionName%" <"%.saveFile%" /time:%.viewTime% /w
choice /T %.DoNextCmd% /C rq /d r /n>nul
if %errorlevel%==2 goto :end
goto :start
:end
:: Clear the used variables
:: Adding a unified symbol "." in front of the used variables is to facilitate variable cancellation :)
for /f "delims==" %%i in ('set .') do set "%%i="
set "dbg="
In the ":Redtek 2006" label code segment, you can change the initial variables according to your own needs.
Principle: Use the MSG message sending system built into the Windows system to complete the message display tool.
The /w parameter of MSG has the function of "blocking execution state" to execute and display the current window. When executing, the system is in a waiting state and exits after completion.
The /TIME parameter of MSG has a time delay function for waiting for the receiver to confirm the message, that is, unless the user actively ends the window, the message will end after the specified n seconds.
In this way, the method of forcibly killing the process to try to close the message display window is replaced.
At the same time, MSG can send the specified message to any computer in the local area network, whether it is broadcasting or specifying the receiver, it can be achieved.
If you use the Ping -n ....<nul command to indirectly achieve the effect of "delay", the CPU will be in a high load state, even up to 90%.
So CHOICE is used to achieve the effect of waiting for delay. After testing, its CPU peak is about 0-2%.
And the function of CHOICE to get the user's selected value can achieve terminating the code operation by pressing the specified key, which is convenient for the user to exit safely during execution.
When executing ARP, its CPU test peak is about 2-13%, which has little impact on the system.
The statement for /f "delims==" %%i in ('set .') do set "%%i=" is set to clear the used variables.
The variables used in the code all start with a ".", so when I finish using them, just one For is enough, no need to list them one by one and then delete them.
This is using SET . When this operation is performed, the system will display all variables starting with ".", and a for will naturally find and "introduce" them all, and then assign an "empty" value to clear the operation.
) Another: If you can't find the CHOICE.EXE file in the Chinese version of Windows XP system, this file is compressed into the attachment of this post together with this code. Friends who need it can download it conveniently : )