Hi All,
I want to collect the IPs for online workstations on my domain and i have two scripts the first script to only display which is the online and the other script to collect the IPs for any host name inside the input file named (hosts.txt).
and i want to merge this two scripts to do what i want which is to ping any host name taken for the input file then try to ping on it and if it's online try to bring it's IP then insert the result into output file but i couldn't
Can Any professional here to assist
here is the mentioned two scripts.
First one to ping all host names and separate them inside two output files.
@echo off
for /f %%i in (hosts.txt) do (
SET bHOSTUP=0
ping -n 1 %%i -w 2000 |find "TTL=" > NUL && SET bHOSTUP=1
IF !bHOSTUP! equ 1 (
set g=%%i
CALL :HOSTUP %%i
) else (
set g=%%i
CALL :HOSTDOWN %%i
)
)
GOTO EOF
:HOSTUP
Echo %g% : Is Pingable
Echo %g% : Is Pingable>>Online_workstations.txt
GOTO EOF
:HOSTDOWN
Echo %g% : is Offline or Not Exist
Echo %g% : is Offline or Not Exist>>Offline_workstations.txt
GOTO EOF
:EOF
exit /B
And Here is the second script which used to collect the IPs for all host names located in the input file also
@echo off
for /F "tokens=* delims=" %%C in (hosts.txt) do (
for /f "tokens=1,2 delims=[]" %%A in ('ping %%C ^| find "Pinging"') do set ipaddress=%%B && echo %%C : %%B
)
I want to merge these two scripts into one batch (one step)( separate online workstations and offline workstations and if found that the workstation is online try to get its IP and insert this information inside the output file.