[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

Pinging multibles and save ing resalts to file

Posted on 2005-04-08
16
Medium Priority
?
261 Views
Last Modified: 2010-04-18
I am runing the comand:    FOR /L %g IN (1,1,254) DO ping -n 2 200.200.200.%g
and I want to save resalts in file so I can Print them off.
0
Comment
Question by:ryanpartridge
  • 9
  • 7
16 Comments
 
LVL 85

Expert Comment

by:oBdA
ID: 13738890
Simply use the redirection:
FOR /L %g IN (1,1,254) DO ping -n 2 200.200.200.%g >SomeTextFile.txt
0
 

Author Comment

by:ryanpartridge
ID: 13739254
I tried this but it maks a *.txt but it over rights when it gos to next IP. I need it to add all IP in on .txt
0
 
LVL 85

Expert Comment

by:oBdA
ID: 13739310
Sorry, with the loop, it should of course have been two "greater" signs; this will add the output to an existing file:
FOR /L %g IN (1,1,254) DO ping -n 2 200.200.200.%g >>SomeTextFile.txt
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:ryanpartridge
ID: 13739338
I Will Try
0
 

Author Comment

by:ryanpartridge
ID: 13741556
it works but can it sort
reply in one file and time out in another

will the IF command do it
0
 

Author Comment

by:ryanpartridge
ID: 13742581
this is some thing I tryed but It do not work


set /p reply=Reply from

FOR /L %%g IN (1,1,5) DO ping -a -n 2 192.168.254.%%g

set /p reply=Reply from

if defined reply >>c:\yy
else >>C:\tt
0
 
LVL 85

Expert Comment

by:oBdA
ID: 13743131
Assuming you only need the IP addresses of the machines which answered (or didn't), try this:

@echo off
setlocal
set ReplyFile=C:\yy.txt
set NoReplyFile=C:\tt.txt
set Net=192.168.254
for /l %%a in (1,1,5) do (
  ping -a -n 2 %Net%.%%a | find /i "TTL" >NUL
  if errorlevel 1 (
    echo No reply from %Net%.%%a
    echo %Net%.%%a >>"%NoReplyFile%"
  ) else (
    echo Reply from %Net%.%%a
    echo %Net%.%%a >>"%ReplyFile%"
  )
)
0
 

Author Comment

by:ryanpartridge
ID: 13744281
in first go. I used PING -a to resolve hostnames
In new script it still uses -a but do not use info. Can this script put this info with replyed IP

 THankyou for all your help.
0
 
LVL 85

Expert Comment

by:oBdA
ID: 13748531
Try this, then:

@echo off
setlocal
set ReplyFile=C:\yy.txt
set NoReplyFile=C:\tt.txt
set TempFile=%Temp%\ping.tmp
set Net=192.168.254
for /l %%a in (1,1,5) do (
  echo Checking %Net%.%%a ...
  ping -a -n 2 %Net%.%%a >"%TempFile%"
  find /i "TTL" "%TempFile%" >NUL
  if errorlevel 1 (
    echo ... no reply from %Net%.%%a
    type "%TempFile%" >>"%NoReplyFile%"
  ) else (
    echo ... reply from %Net%.%%a
    type "%TempFile%" >>"%ReplyFile%"
  )
)
del "%TempFile%"
0
 

Author Comment

by:ryanpartridge
ID: 13749052
Thank you,
what does that last comand do?

Is there a way to put just hostname and IP adress in the reply.txt only(single line)

I all so have another script "Q" I have asked about shuting down a linux box from windows serve at power lose to windows box. windows box and linux box is pluged into a battery backup(window box is hooked in by usb to battery) but I would like to shut down linux box properly.
0
 
LVL 85

Expert Comment

by:oBdA
ID: 13750891
@echo off
setlocal
set ReplyFile=C:\yy.txt
set NoReplyFile=C:\tt.txt
set TempFile=%Temp%\ping.tmp
set Net=192.168.254
for /l %%a in (1,1,5) do (
 echo Checking %Net%.%%a ...
 ping -a -n 2 %Net%.%%a >"%TempFile%"
 find /i "TTL" "%TempFile%" >NUL
 if errorlevel 1 (
   echo ... no reply from %Net%.%%a
   type "%TempFile%" >>"%NoReplyFile%"
 ) else (
   echo ... reply from %Net%.%%a
   for /f "skip=2 tokens=2" %%i in ('find /i "[%Net%.%%a]" "%TempFile%"') do echo %Net%.%%a %%i >>"%ReplyFile%"
 )
)
del "%TempFile%"
0
 

Author Comment

by:ryanpartridge
ID: 13753504
can you tell me why? if it does not have a hostname it does not put the adress in the reply .txt
when i ping 1-5.  I get reply from 1, 2 and 3. 1 does not show up in .txt. I is my router and it does not give me a hostname.
0
 
LVL 85

Expert Comment

by:oBdA
ID: 13754080
Assuming you have a DNS server, use this then:

@echo off
setlocal
set ReplyFile=C:\yy.txt
set NoReplyFile=C:\tt.txt
set TempFile=%Temp%\ping.tmp
set Net=192.168.254
for /l %%a in (1,1,5) do call :process %%a
goto leave

:process
echo Checking %Net%.%1 ...
ping -n 2 %Net%.%1 | find /i "TTL" >NUL
if errorlevel 1 (
  echo ... no reply from %Net%.%1
  echo %Net%.%1 >>"%NoReplyFile%"
  goto :eof
)
set HostName=Not resolvable
for /f "tokens=2" %%a in ('nslookup %Net%.%1 2^>NUL ^| find /i "Name:"') do set HostName=%%a
echo ... reply from %Net%.%1 [%HostName%]
echo %Net%.%1 %HostName% >>"%ReplyFile%"

:leave
0
 

Author Comment

by:ryanpartridge
ID: 13754578
Command Prompt:

Check 192.168.254.1.....
.....reply from 192.168.254.1 [Not resolvable]
Check 192.168.254.2.....
.....reply from 192.168.254.1 [2-dc.pne.local]
Check 192.168.254.3.....
.....reply from 192.168.254.3 [out.pne.local]
Check 192.168.254.4.....
.....no reply from 192.168.254.4
Check 192.168.254.5.....
.....no reply from 192.168.254.5
the system cannot find the batch label specified - leave

It runs but it only gives me a tt.txt(no reply). the yy.txt(reply) does not seem to be created
 
0
 
LVL 85

Accepted Solution

by:
oBdA earned 840 total points
ID: 13766253
Hm? Works fine for me. Make sure you copied the complete script (everything between--but excluding--the two cutting lines); at least the last line with the label ":leave" is missing.
Oh, and you can lose the "TempFile" definition at the beginning, that sneaked back in ...

====8<----[pingtest.cmd]----
@echo off
setlocal
set ReplyFile=C:\yy.txt
set NoReplyFile=C:\tt.txt
set Net=192.168.254
for /l %%a in (1,1,5) do call :process %%a
goto leave

:process
echo Checking %Net%.%1 ...
ping -n 2 %Net%.%1 | find /i "TTL" >NUL
if errorlevel 1 (
 echo ... no reply from %Net%.%1
 echo %Net%.%1 >>"%NoReplyFile%"
 goto :eof
)
set HostName=Not resolvable
for /f "tokens=2" %%a in ('nslookup %Net%.%1 2^>NUL ^| find /i "Name:"') do set HostName=%%a
echo ... reply from %Net%.%1 [%HostName%]
echo %Net%.%1 %HostName% >>"%ReplyFile%"

:leave
====8<----[pingtest.cmd]----
0

Featured Post

New feature and membership benefit!

New feature! Upgrade and increase expert visibility of your issues with Priority Questions.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This may not be a text book method to resolve VSS backup issues but it seemed to have worked on few of the Windows 2003 servers we had issues while performing a Volume Shadow Copy backup. If you have issues while performing a shadow copy backup usin…
While rebooting windows server 2003 server , it's showing "active directory rebuilding indices please wait" at startup. It took a little while for this process to complete and once we logged on not all the services were started so another reboot is …
Please read the paragraph below before following the instructions in the video — there are important caveats in the paragraph that I did not mention in the video. If your PaperPort 12 or PaperPort 14 is failing to start, or crashing, or hanging, …
Screencast - Getting to Know the Pipeline

829 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question