|
Answer» Hello All, Need a little help. I am wanting to create a simple batch file to ping several known IP Addresses from within my NETWORK. I need to make this utility for my comrades at work when I am not there to FIND the problem.
I am wanting to ping an IP Address, then if it does return, state SUCCESSFUL, or if it fails, return the IP Address and a name I assign to that address, then move to the next.
Any help appreciated Davids Learning You can read out the pcnames from a hostlist with a for loop to ping and analyze the output
findstr gives you errorlevel 0 if it finds the string, errorlevel 1 if it doesn't find it. The FOLLOWING code works on my machine. (Depends what the output of ping ins on your machine. I use german language version.
hope it helps uli
@echo off setlocal FOR /F %%h IN (hosts.txt) do call :ping %%h echo.
goto :eof :ping set PC=%1
REM check if PC is online. ping -n 1 %PC% | findstr Timeout IF %ERRORLEVEL% EQU 1 (echo %PC% >> pc_online.txt
endlocal
:EOF
I appreciate you responding, but I need to be able to ping specific IP's with a name that I assign. The pc's here do not have the users name. The people here wont understand what the names are and where they are. I have got to keep the response so that its simple for the others to understand.
I was wanting to return like
Timmys PC - Found OK Tonys PC - Not Found - Problem Internet Provider - Found - OK
The first 2 would be IP addresses The second would be a Web Site ping
Thanks Davis Learning So you want just a single ip adress with names? You need a list with all pcs like this:
Tommy:1.27.111.111 Mad:1.7.222.222 ....
Use it like: Script tommy
@echo off setlocal if {%1} == {} (echo please type a pc name & goto :EOF) set USER=%1
FOR /F "tokens=1,2 delims=:" %%h in ('find /i "%USER%" hosts.txt') do call :ping %%h %%i
goto :eof :ping %%h %%i set USER=%1 set IP=%2
REM check if PC is online. ping -n 1 %IP% | findstr Timeout IF %ERRORLEVEL% EQU 1 (echo %USER%s PC -OK >> pc_online.txt IF %ERRORLEVEL% EQU 0 (echo %USER%s PC - Not OK >> pc_online.txt endlocal :EOF
This should work (hopefully ;-)) Uli
|