1

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!"
Hackoo
  • 18,337
  • 3
  • 40
  • 70
K0D3-BLU3
  • 31
  • 2

1 Answers1

0

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!"
Paul Houle
  • 735
  • 9
  • 17
  • Thank you im pretty new to it all and writing up on my mobile so havent actually ran it as im away from my laptop. i will note that as its more or less what i was after but what i intended to do was to automatically open cmd if packets were recieved back, if not then nothing happens, but continue to automatically run commands in cmd afterwards – K0D3-BLU3 Jun 10 '17 at 20:59