

InterviewSolution
Saved Bookmarks
1. |
Solve : Batch to ping network range? |
Answer» <html><body><p>Trying to make a program to ping network range.<br/>the range is selected via SET /p and later called in the following segment. (I believe this is where I'm having issues.)<br/> Code: <a>[Select]</a>PING -n 1 %range%.2|find "reply from " >NUL<br/>IF NOT ERRORLEVEL 1 goto s1<br/>IF ERRORLEVEL 1 goto f1<br/>s1 echos a success script and will nbtstat the successful IP<br/>f1 returns fail and <a href="https://interviewquestions.tuteehub.com/tag/continues-2542063" style="font-weight:bold;" target="_blank" title="Click to know more about CONTINUES">CONTINUES</a> onto the next IP in the range<br/><br/>Is PING.exe reading the IP literally and thus <a href="https://interviewquestions.tuteehub.com/tag/returning-1187974" style="font-weight:bold;" target="_blank" title="Click to know more about RETURNING">RETURNING</a> false?<br/><br/>the target range was tested and showed a .....0.2 ip in the range.<br/><br/>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%)<br/><br/> Quote</p><blockquote>Is PING.exe reading the IP literally .. ?</blockquote> <br/>Not <a href="https://interviewquestions.tuteehub.com/tag/sure-656539" style="font-weight:bold;" target="_blank" title="Click to know more about SURE">SURE</a> what you mean by this.<br/><br/><br/><br/>It will run as so...<br/><br/> Code: <a>[Select]</a>set /p range= Please select Range: Quote<blockquote>user sees: Please select range:<br/>User types: 192.168.1<br/>Program runs: Code: <a>[Select]</a>ping -n 1 192.168.1.1 | find "reply" >nul<br/> IF NOT ERRORLEVEL 1 goto success<br/> IF ERRORLEVEL 1 goto fail</blockquote> It will loop till 254 on that range<br/> Quote from: Phuhrenzix on <a href="https://interviewquestions.tuteehub.com/tag/october-584768" style="font-weight:bold;" target="_blank" title="Click to know more about OCTOBER">OCTOBER</a> 27, 2010, 11:04:57 AM<blockquote>It will loop till 254 on that range<br/></blockquote> <br/>What do you mean by this?<br/><br/>it will start on 192.168.1.1 and end in 192.168.1.254 in this example.<br/>(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<blockquote>it will start on 192.168.1.1 and end in 192.168.1.254 in this example.<br/></blockquote> <br/>How does it do that?<br/>here, i'm probably not explaining well enough.<br/> Code: <a>[Select]</a>echo off<br/>SET /p username=User Name:<br/>SET /p password=Password:<br/>IF %password%==foo goto start<br/>ELSE goto try1<br/>:try1<br/>echo login failed 1/3<br/>SET /p password=Password:<br/>IF %password%==foo goto start<br/>:try2<br/>ELSE goto try2<br/>echo login failed 2/3<br/>SET /p password=Password:<br/>IF %password%==foo goto start<br/>ELSE goto try3<br/>:try3<br/>echo login failed 3/3<br/>SET /p password=Password:<br/>IF %password%==foo goto start<br/>ELSE goto end<br/>:start<br/>set /p range=please enter range:<br/>Echo sniff sniff sniff<br/>:1<br/>PING -n 1 %range%.1 |find "reply" >NUL<br/>IF NOT ERRORLEVEL 1 goto s1<br/>IF ERRORLEVEL 1 goto f1<br/>:s1<br/>echo sniff sniff sniff, %range%.1 lives!<br/>:f1<br/>echo whimper, sorry Master %username% I could not find %range%.1<br/>goto 2<br/>:2<br/>PING %range%.2|find "reply from " >NUL<br/>IF NOT ERRORLEVEL 1 goto s2<br/>IF ERRORLEVEL 1 goto <a href="https://interviewquestions.tuteehub.com/tag/f2-456229" style="font-weight:bold;" target="_blank" title="Click to know more about F2">F2</a><br/>:s1<br/>echo sniff sniff sniff, %range%.1 lives!<br/>goto 3<br/>:f1<br/>echo whimper, sorry Master %username% I could not find %range%.1<br/>goto 2<br/>.<br/>.<br/>.<br/>:end<br/>You seem to think that the ping command will ping a range of IP addresses, but you are only giving it one IP address.<br/><br/>it continues on<br/>:1 area pings %range%.1<br/>:2 area pings %range%.2<br/>:3 area pings %range%.3<br/> and so on<br/><br/><br/>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?<br/><br/>1. Why???<br/>2. Why did you not mention this before?<br/>3. What are you trying to do here? Is it some kind of hack?<br/><br/><br/><br/>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<br/>2. I was just with bad word choice<br/>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.<br/>2. This is how to loop through a range of numbers using FOR<br/><br/> Code: <a>[Select]</a>REM example<br/>set range=192.168.1<br/>for /L %%N in (1,1,254) do PING %range%.%%N | find "Reply">nul && echo Reply from %range%.%%N<br/>I'm finally seeing results from this.... however, the return is returning even failed pings. Code: <a>[Select]</a>echo off<br/>REM example<br/>set range=192.168.1<br/>set num=1<br/>:loop<br/>PING -n 1 %range%.%num% | find "Reply from"> nul<br/>if %errorlevel% equ 0 (<br/> echo %range%.%num% YES<br/>) else (<br/> echo %range%.%num% NO<br/> ) <br/>set /a num+=1<br/>if %num% equ 255 goto next<br/>goto loop<br/>:next<br/>echo Completed pinging range %range% <br/>This is an awesome fix thanks, just one question though; why is the router not returning as existent?</body></html> | |