K0D3-BLU3
K0D3-BLU3

Reputation: 31

Batch scripting.. i want to run a command automatically based upon user input

writing a script so that when a certain value is returned it opens cmd. Then using a value that the user has added automatically run a command in cmd. not sure if this is even possible or not but any help would be appreciated. Thanks

Edited - the code before

:OpekaiNetReset
echo "Target IP; host is DOWN!"
echo Enter your target IP
set/p TargetIP="Enter your target IP"
ping %TargetIP%
IF %TargetIP%==packets recieved +1 start cmd.exe
IF %TargetIp%==packets recieved 0 goto OpekaiNetReset
:OpekaiCMD
cls
echo "Target IP; host is UP!"

Upvotes: 1

Views: 90

Answers (1)

Paul Houle
Paul Houle

Reputation: 735

Just taking a wing at things, not being sure exactly what you want -- I commented out a few of your lines via :: and added replacements. The below should at least tell you if a host is up/down based on received packets from ping. Unsure what you meant by running cmd.exe on a certain count? The below runs command if the received packet count is 1.

:OpekaiNetReset
echo "Target IP; host is DOWN!"
::echo Enter your target IP
set/p TargetIP="Enter your target IP: "

::ping %TargetIP%
set received=0
for /f "tokens=2 delims=," %%p in ('ping %TargetIP%^|find /i "received"') do set /a %%p
echo packets received == %received%
::IF %TargetIP%==packets recieved +1 start cmd.exe
if %received%==1 start cmd.exe & exit /b
::IF %TargetIp%==packets recieved 0 goto OpekaiNetReset
if %received%==0 goto OpekaiNetReset

:OpekaiCMD
cls
echo "Target IP; host is UP!"

Upvotes: 0

Related Questions