Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7838603
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T15:09:24+00:00 2026-06-02T15:09:24+00:00

The script in its current form @echo on setlocal EnableDelayedExpansion set /p ipAddress=enter ip

  • 0

The script in its current form

@echo on

setlocal EnableDelayedExpansion

set /p ipAddress="enter ip address: "

rem right now the loop is set to (1,1,50) for the sake of testing

for /l %%i in (1,1,50) do (
ping -n 1 %ipAddress%.%%i | find "TTL" > nul

if !errorlevel! == 0 (
deploy_mir.bat %ipAddress%.%%i

)
)

endlocal

and then the result of running it on a known to be online host (10.167.194.22) is

C:\DOCUME~1\socuser2\MIR>test.bat

C:\DOCUME~1\socuser2\MIR>setlocal EnableDelayedExpansion

C:\DOCUME~1\socuser2\MIR>set /p ipAddress="enter ip address: "
enter ip address: 10.167.194

C:\DOCUME~1\socuser2\MIR>for /L %i in (22 1 50) do (
ping -n 1 10.167.194.%i   | find "TTL"  1>nul
if !errorlevel! == 0 (deploy_mir.bat 10.167.194.%i )
)

C:\DOCUME~1\socuser2\MIR>(
ping -n 1 10.167.194.22   | find "TTL"  1>nul
if !errorlevel! == 0 (deploy_mir.bat 10.167.194.22 )
)
"Mir Agent deployment to: 10.167.194.22"

Now that last line there means that !errorlevel! == 0 (ie, “TTL” was indeed found)
so up to this point it looks like the script is working. However on the next loop, 10.167.194.23 (alive) got skipped as well as .30 and .46 . I decided to add

echo %errorlevel% 

at the end of the loop to see whats going on here. Apparently, after every ping %errorlevel% was 0 so clearly

ping -n %ipAddress%.%%i | find "TTL" >nul

is where my issue is. According to this statement, “TTL” is being found after every ping, which is false, between 10.167.194.22-.50 only 3 machines are alive.

by the way, when i do

!errorlevel! == 0

what does that mean?

Everything below this line is as of 4/26/12

So my new script looks like this 

@echo on


set /p ipAddress="enter ip address: "


set i=
for /l %%i in (1,1,255) do (
ping -n 1 %ipAddress%.%%i> test.txt
find "TTL" test.txt
if %errorlevel% == 0 (
deploy_this.bat %ipaddress%.%%i
)

i first tried the script without the if errorlevel check,
and it worked fine. It started pinging the ip address that i provided and proceeded to .2 .3 .4 .5 and so on.

once i added this however…

if %errorlevel% == 0 (
deploy_this.bat %ipaddress%.%%i
)

this is what happens

C:\DOCUME~1\socuser2\MIR>test.bat
C:\DOCUME~1\socuser2\MIR>set /p ipAddress="enter ip address: "
enter ip address: 10.167.201
C:\DOCUME~1\socuser2\MIR>set i=
C:\DOCUME~1\socuser2\MIR>

and the script just stops dead. any ideas?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-02T15:09:25+00:00Added an answer on June 2, 2026 at 3:09 pm

    There are a few issues :

    • A batch file will never return unless you use the call statement
    • You are missing a parenthesis
    • Inside a FOR loop, you must enabledelayedexpansion and use !ERRROLEVEL!

    I suggest you look at this code, it has a few improvements :

    • It use setlocal to keep its variable to itself
    • It does not produce a temp file
    • Can take the ip address from the command line or prompt for it
    • It is indented
    • It is less verbose in its output

    Here it is :

    @echo off
    
    setlocal EnableDelayedExpansion
    
    set ipAddress=%1
    
    if "%ipAddress%"=="" SET /P ipAddress="enter ip address: "
    
    for /l %%i in (1,1,2) do (
    
        rem Remove the > nul at the end if you want to 
        rem see the ping results in the output
        ping -n 1 %ipAddress%.%%i | find "TTL" > nul
    
        if !ERRORLEVEL! == 0 (
           call deploy_this.bat %ipAddress%.%%i
        )
    )
    
    endlocal
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

How do I detect from within a shell script if its standard output is
How can I call a PHP script from a Perl script and get its
I'm maintaining a script that can get its input from various sources, and works
I have a script in Bash called Script.sh that needs to know its own
I have a JS script (widget) which is added to other websites. Technically its
I've made script which change information from different site, its occure when i click
I have made a script that uses a program called Diascope, its a video
I have a VBA script that imports a layout into an exsting drawing, its
I am trying to run a cgi script, its a long script so i
I am noticing some weird behavior in my script, not sure why its occurring

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.