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 : )