Question:

How do IF Statments work in DOS/BATCH?

by  |  earlier

0 LIKES UnLike

I need a batch script which will ping a list of IP addresses, if the IP's do not respond, I want it to beep and pause the script. I know how to do the pinging, but I do not know how IF Statements work within DOS, do I need to assign the answer of the ping to a variable? Thanks

Tom

 Tags:

   Report

2 ANSWERS


  1. check these websites

    http://academic.evergreen.edu/projects/b...

    http://www.infionline.net/~wtnewton/batc...

    http://www.robvanderwoude.com/if.html


  2. This may not be exactly what you are looking for but this code works. Where it says x.x.x%A% replace the three x's with the range you want to ping such as 127.8.9. You will fill in the last number in the command prompt. It will not beep or pause when it gets an unresponsive host but it does log everything in a log file, "C:\PING_RESULTS.txt" You might need to run this as an administrator.

    @ECHO OFF

    :main

    IF EXIST C:\PING_RESULTS.txt DEL C:\PING_RESULTS.txt

    ECHO Ping Test Ran on %date% at %time% >> C:\PING_RESULTS.txt

    ECHO.

    :GETIPS

    ECHO Enter Range of IP's to Ping in the 192.168.1 subnet

    ECHO.

    SET /P A="Please enter the first number in the range of IP addresses: "

    SET /P B="Please enter the last number in your range of IP addresses to ping: "

    Echo Results for ping test between 192.168.1.%A% and 192.168.1.%B% are as follows: >> C:\PING_RESULTS.txt

    :PING

    ping -a x.x.x.%A% >> C:\PING_RESULTS.txt

    IF %A%==%B% GOTO FINISH

    SET /a A=%A%+1

    ECHO %A%

    GOTO PING

    :FINISH

    set /p yes=Would you like to ping any more addresses (y/n)?

    if %yes%==y goto GETIPS

    START C:\PING_RESULTS.TXT

Question Stats

Latest activity: earlier.
This question has 2 answers.

BECOME A GUIDE

Share your knowledge and help people by answering questions.