Link to home
Start Free TrialLog in
Avatar of ryanpartridge
ryanpartridge

asked on

Pinging multibles and save ing resalts to file

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.
Avatar of oBdA
oBdA

Simply use the redirection:
FOR /L %g IN (1,1,254) DO ping -n 2 200.200.200.%g >SomeTextFile.txt
Avatar of ryanpartridge

ASKER

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
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
I Will Try
it works but can it sort
reply in one file and time out in another

will the IF command do it
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
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%"
  )
)
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.
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%"
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.
@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%"
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.
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
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
 
ASKER CERTIFIED SOLUTION
Avatar of oBdA
oBdA

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial