|
Answer» 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.
Code: [Select]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
Code: [Select] 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.Hi Just give a try for the combined script and tell me the results on your side !
Scan_Hosts_IP.bat
Code: [Select]echo off Title Collect all IPs For online workstations only on my domain Set "HOSTS_File=%~dp0hosts.txt"
IF NOT EXIST "%HOSTS_File%" ( Color FC ECHO( Echo( Please Check this "%HOSTS_File%" location with this script "%~nx0" TimeOut /T 8 /NoBreak>nul EXIT )
Set "LogFile_OnLine=%~dp0_Online_workstations.txt" If Exist "%LogFile_OnLine%" Del "%LogFile_OnLine%" Set "LogFile_OffLine=%~dp0_Offline_workstations.txt" If Exist "%LogFile_OffLine%" Del "%LogFile_OffLine%"
SetLocal EnableDelayedExpansion for /f %%i in ('Type "%HOSTS_File%"') do ( SET bHOSTUP=0 Ping -n 1 %%i -w 2000 |find "TTL=">NUL && SET bHOSTUP=1 IF [!bHOSTUP!] equ [1] ( set "HostName=%%i" Call :GET_IP %%i CALL :HOSTUP %%i ) else ( set "HostName=%%i" CALL :HOSTDOWN %%i ) )
START "Log" /MAX "%LogFile_OnLine%" GOTO EOF ::---------------------------------------------------------------------- :HOSTUP IF defined IP ( Echo !HostName! : Is Pingable - IP = !IP! Echo !HostName! : Is Pingable - IP = !IP!>>"%LogFile_OnLine%" ) Else ( Echo !HostName! : Is Pingable Echo !HostName! : Is Pingable>>"%LogFile_OnLine%" ) GOTO EOF ::---------------------------------------------------------------------- :HOSTDOWN Echo !HostName! : is Offline or Not Exist Echo !HostName! : is Offline or Not Exist>>"%LogFile_OffLine%" GOTO EOF ::---------------------------------------------------------------------- :GET_IP <HOST> <IP> Set "IP=" for /f "tokens=2 delims=[]" %%b in ('ping -n 1 %1') do Set "IP=%%b" Exit /B ::---------------------------------------------------------------------- :EOF exit /B ::----------------------------------------------------------------------Hi For who is still interested for any improved of this Batch script : You can found it here for any update : Scanner_IP_MAC_Colors.bat Have a nice day Thanks, Hackoo for appreciate helping
|