JSI Tip 1291. Generate a report of IPaddresses, ComputerNames, and UserNames, currently logged onto your domain.

I have scripted the subject report, in a format similar to: \\ALRMP                  Jerry \\DELL                   Jennifer
The script uses SOON and SLEEP from the Server Resource Kit Supplement 4.

If you don't have SOON, create your own.

if you don't have SLEEP, use a PAUSE.

There are two (2) batch files required. The controlling script is WhatIpDCsubmit.bat. The syntax is:

WhatIpDCsubmit WhatIpDC.bat ReportFile DC1 \[DC2 DC3 ... DCn\]       where:

    WhatIpDC.bat      is the full path to the WhatIpDC.bat file. 
    ReportFile      is the full path to the output report file. 
    DCx      is the ComputerName of each domain controller. 

NOTE: You must adjust the SLEEP time (currently 900 seconds (15 minutes)) to insure the scheduled jobs finish.

WhatIpDCsubmit.bat contains:

@echo off
if /i not \{%3\}

\{\} goto begin :syntax @echo Syntax: WhatIpDCsubmit WhatIpDC.bat ReportFile DC1 \[DC2 DC3 ... DCn\] endlocal goto end :begin set whatip=%1 if not exist %whatip% goto syntax set file=%2 set folder=%~DP2 if exist %File% del /f /q %file% if exist "%folder%WhatIpDc.tm*" del /f /q "%folder%WhatIpDc.tm*" copy %whatip% c:\WhatIpDc.bat shift :loopdc shift if \{%1\}

\{\} goto report set dc=%1 set dc=%dc:\=% set dc=%dc:"=% if exist "\\%dc%\c$\WhatIpDc.log" del /f /q "\\%dc%\c$\WhatIpDc.log" copy %whatip% "\\%dc%\c$\WhatIpDc.bat" REM If you don't have soon, create your own. soon "\\%dc%" 90 cmd /c "c:\whatIpDc.bat" @echo %dc% >> "%folder%WhatIpDc.tm1" goto loopdc :report REM if you don't have sleep, use a pause. You must allow enough time for completion sleep 900 for /f "Tokens=*" %%i in ('type "%folder%WhatIpDc.tm1"') do call :checkdc "%%i" sort
WhatIpDC.bat contains:
@echo off
for /f "Skip=4 Tokens=*" %%i in ('net session') do call :parse "%%i"
goto end
set str=%1
set str=%str:"=%
if "%str%"

"The command completed successfully." goto end for /f "Tokens=*" %%i in ('@echo %%str:~23^,1%%') do set substr=%%i if "%substr%"

"ECHO is on." goto end set computer=%str:~0,15%# set computer=%computer: #=#% set computer=%computer: #=#% set computer=%computer: #=#% set computer=%computer: #=#% set computer=%computer:#=% set user=%str:~23,20% for /f "Tokens=1-6 Delims=\[\].: " %%i in ('ping -a -n 1 "%computer:~2,12%"') do call :parse1 %%i %%k %%l %%m %%n set computer=%computer% # set computer=%computer:~0,15% @echo %ip% %computer% %user% >> c:\WhatIpDc.log goto end :parse1 if /i not "%1"=="Reply" goto end set ip=%2.%3.%4.%5 :end

Hide comments


  • Allowed HTML tags: <em> <strong> <blockquote> <br> <p>

Plain text

  • No HTML tags allowed.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Lines and paragraphs break automatically.