[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 990
  • Last Modified:

ping command output to a batch file

I want to ping all workstations on my network from a batch file and put the results off this in notepad.  how would i do this?
0
cgalle
Asked:
cgalle
1 Solution
 
knightEknightCommented:
Do you have the names (or IPs) of all your workstations in a text file?
0
 
cgalleAuthor Commented:
yes.

example:
@echo on

ping 10.100.1.1 -n 1
ping 10.100.1.2 -n 1
ping 10.100.1.3 -n 1
ping 10.100.1.4 -n 1
ping 10.100.1.5 -n 1
0
 
Steve KnightIT ConsultancyCommented:
If they follow a known IP range bes bet is to use a loop. This is one I use:


@echo off
set subnet=10.100.1
del iplog.txt 2>NUL
for /l %%a in (1,1,254) do call :checkip %%a
start iplog.txt
goto :Eof

:checkip
ping -n 1 -w 100 %subnet%.%1 | find "Reply from" > NUL 2>&1
if not "%errorlevel%"=="0" echo 192.168.5.%1 not responding & goto :eof
set name=Unknown
for /f "tokens=2 delims=: " %%n in ('nslookup %subnet%.%1 ^| find "Name:"') do set name=%%n
echo %subnet%.%1 (%name%) is responding
echo %subnet%.%1,%name%>>iplog.txt

Steve
0
Efficient way to get backups off site to Azure

This user guide provides instructions on how to deploy and configure both a StoneFly Scale Out NAS Enterprise Cloud Drive virtual machine and Veeam Cloud Connect in the Microsoft Azure Cloud.

 
Steve KnightIT ConsultancyCommented:
Replace the 192.168.5 bit with %subnet% again, there missed it in the search/replace.

Steve
0
 
cgalleAuthor Commented:
dragon-it:
when i run your file it get the following:
the process cannot access the file because it is being used by another process.
0
 
Steve KnightIT ConsultancyCommented:
Odd?  If you run it from a cmd.exe prompt does it show any other output?  Can it write to the iplog.txt file in the current directory OK?
0
 
joshlunsfordCommented:
@echo off
set network=10.100.1.
set machine=1
set logfile=c:\logfile.txt
:loop
ping +-n 1 -w 100 %network%%machine%  | find "Reply from" > NUL 2>&1
if "%errorlevel%"=="0" echo %network%%machine% valid ip > %logfile%
set /a machine=%machine% + 1
if /I %machine% GEQ 255 goto :EOF
goto loop
0
 
Steve KnightIT ConsultancyCommented:
Did it work in the end then.  Presume you never got to the bottom of why my (working) solution was givng you an error?
0

Featured Post

Prep for the ITIL® Foundation Certification Exam

December’s Course of the Month is now available! Enroll to learn ITIL® Foundation best practices for delivering IT services effectively and efficiently.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now