1.

Solve : Batch to ping network range?

Answer»

Trying to make a program to ping network range.
the range is selected via SET /p and later called in the following segment. (I believe this is where I'm having issues.)
Code: [Select]PING -n 1  %range%.2|find "reply from " >NUL
IF NOT ERRORLEVEL 1 goto s1
IF ERRORLEVEL 1 goto f1
s1 echos a success script and will nbtstat the successful IP
f1 returns fail and CONTINUES onto the next IP in the range

Is PING.exe reading the IP literally and thus RETURNING false?

the target range was tested and showed a .....0.2 ip in the range.

EDIT** Changed the SET /p to a set IP still returning false when ARP is returning that the IP exists.could you give an example of a range that might be typed in using set /p? (that is a typical value of %range%)

Quote

Is PING.exe reading the IP literally .. ?

Not SURE what you mean by this.



It will run as so...

Code: [Select]set /p range= Please select Range: Quote
user sees: Please select range:
User types: 192.168.1
Program runs: Code: [Select]ping -n 1 192.168.1.1 | find "reply" >nul
                        IF NOT ERRORLEVEL 1 goto success
                        IF ERRORLEVEL 1 goto fail
It will loop till 254 on that range
                        Quote from: Phuhrenzix on OCTOBER 27, 2010, 11:04:57 AM
It will loop till 254 on that range

What do you mean by this?

it will start on 192.168.1.1 and end in 192.168.1.254 in this example.
(the code is highly redundant because I couldn't get the FOR to loop and echo properly) Quote from: Phuhrenzix on October 27, 2010, 11:18:26 AM
it will start on 192.168.1.1 and end in 192.168.1.254 in this example.

How does it do that?
here, i'm probably not explaining well enough.
Code: [Select]echo off
SET /p username=User Name:
SET /p password=Password:
IF %password%==foo goto start
ELSE goto try1
:try1
echo login failed 1/3
SET /p password=Password:
IF %password%==foo goto start
:try2
ELSE goto try2
echo login failed 2/3
SET /p password=Password:
IF %password%==foo goto start
ELSE goto try3
:try3
echo login failed 3/3
SET /p password=Password:
IF %password%==foo goto start
ELSE goto end
:start
set /p range=please enter range:
Echo sniff sniff sniff
:1
PING -n 1  %range%.1 |find "reply" >NUL
IF NOT ERRORLEVEL 1 goto s1
IF ERRORLEVEL 1 goto f1
:s1
echo sniff sniff sniff, %range%.1 lives!
:f1
echo whimper, sorry Master %username% I could not find %range%.1
goto 2
:2
PING %range%.2|find "reply from " >NUL
IF NOT ERRORLEVEL 1 goto s2
IF ERRORLEVEL 1 goto F2
:s1
echo sniff sniff sniff, %range%.1 lives!
goto 3
:f1
echo whimper, sorry Master %username% I could not find %range%.1
goto 2
.
.
.
:end
You seem to think that the ping command will ping a range of IP addresses, but you are only giving it one IP address.

it continues on
:1 area pings %range%.1
:2 area pings %range%.2
:3 area pings %range%.3
 and so on


like i said it is highly redundant and has a instance for 1-254 to ping, the actual code isnt one IP address, unless it's only pinging what is entered for range.You mean you have 254 separate labels and 254 separate sections? Is this true?

1. Why???
2. Why did you not mention this before?
3. What are you trying to do here? Is it some kind of hack?



1. because I want it to return if the IP's are existant on the network. and the FOR wouldn't run the echo's properly
2. I was just with bad word choice
3. This is an alternative to ARP(which doesnt return IP's on public networks) on public networks to be used by network administrators. If you want to think of it as a hack in that element, yes. If you're thinking it is a hack as in illegal, no. 1. Either make the string for FIND to be "Reply" with a capital R or else make the find case-insensitive with the /I switch.
2. This is how to loop through a range of numbers using FOR

Code: [Select]REM example
set range=192.168.1
for /L %%N in (1,1,254) do PING %range%.%%N | find "Reply">nul && echo Reply from %range%.%%N
I'm finally seeing results from this.... however, the return is returning even failed pings. Code: [Select]echo off
REM example
set range=192.168.1
set num=1
:loop
PING -n 1 %range%.%num% | find "Reply from"> nul
if %errorlevel% equ 0 (
echo %range%.%num% YES
) else (
echo %range%.%num% NO
)
set /a num+=1
if %num% equ 255 goto next
goto loop
:next
echo Completed pinging range %range%
This is an awesome fix thanks, just one question though; why is the router not returning as existent?


Discussion

No Comment Found