Script to Find DNS Server settings.

Script to find DNS settings:

 

  1. You can use up to Four Login attempts to check authentication on different servers or domains.
  2. Results get stored in a CSV format file. File name: Report.CSV
  3. Command window display for script information.
  4. Script supplies error message exactly.
  5. Servers Up/Down Status.

 

 

 

@echo off

 

@echo  =====================================================

@Echo  Script to Find DNS Servers configured for each server

@echo  =====================================================

 

@echo Please Enter Server List Path (e.i. E:\Nirmal\Srvlist\mgmsrv.txt)

 

setlocal enabledelayedexpansion

 

set /P srvlist=” “

 

IF exist %srvlist% (

  Echo Server list found: %srvlist%

  Echo Processing all the servers from %srvlist%

  CLS

 

) ELSE (

  CLS

  Echo Server list NOT found: %srvlist%

  Echo Exiting…

  goto:EOF

 

)

 

  SET DNS_Conf=

  SET Int_Logon=

  SET ComERRSRM=

  SET SNK_login=

  SET ComERRSNK=

  SET AMU_Login=

  SET Fold_Drive=

  SET Fold_Loc=

  SET REG_Upload=

  SET REG_Use=

  SET ServerStat=

  SET LOR_NEW=

  SET LOR_OLD=

  SET DLS_B=

  SET BIAS_B=

  SET DLS_A=

  SET BIAS_A=

  SET Rem_Req=

  SET PSEXEC_SPU=

  SET DST_Stat=

  SET AOS_Ver=

  SET AOS_Folder=

  SET AOS_Un=

  SET Uninst_Fold=

  SET Os_SRMto_E=

  SET Final_login=

  SET ComERR=

  SET NewComERR=

  SET Method_U=

  SET Copy_Un_F=

  SET DST_Source=

  SET DST_Dest=

 

set /a totsrv=0

set /a totcnt=0

 

FOR /F %%a in (%srvlist%) DO SET /a totsrv=!totsrv!+1

 

  SET SNK_login=

  SET Loc_Power=

  SET ComERRSNK=

  SET ComERRSRM=

  SET AMU_Login=

  SET ServerStat=

  SET LOR_NEW=

  SET LOR_OLD=

  SET DLS_B=

  SET Int_Logon=

  SET DNS_Conf=

  SET PSEXEC_TZ=

  SET Rem_Req=

  SET PSEXEC_SPU=

  SET AOS_Ver=

  SET AOS_Folder=

  SET AOS_Un=

  SET Uninst_Fold=

  SET Os_SRMto_E=

  SET Final_login=

  SET ComERR=

  SET NewComERR=

  SET PS_Rem=

  SET Method_U=

  SET Copy_Un_F=

  SET DST_Source=

  SET DST_Dest=

  SET Fold_Drive=

  SET Fold_Loc=

  SET Search_C=

  SET Search_D=

  SET Search_E=

 

Title DNS Server script in Progress…

 

IF exist E:\Nirmal\Dns\Report.csv Del E:\Nirmal\Dns\Report.csv

IF exist E:\Nirmal\Dns\Dnssrv.csv Del E:\Nirmal\Dns\DnsSrv.csv

IF exist E:\Nirmal\Dns\HostsAlive.txt Del E:\Nirmal\Dns\HostsAlive.txt

IF exist E:\Nirmal\Dns\HostsDown.txt Del E:\Nirmal\Dns\HostsDown.txt

IF exist E:\Nirmal\Dns\Alreadydone.txt Del E:\Nirmal\Dns\AlreadyDone.txt

IF exist E:\Nirmal\Dns\ToBeDone.txt Del E:\Nirmal\Dns\ToBeDone.txt

IF exist E:\Nirmal\Dns\RemovedDST.txt Del E:\Nirmal\Dns\RemovedDST.txt

IF exist E:\Nirmal\Dns\RemoveFailed.txt Del E:\Nirmal\Dns\RemoveFailed.txt

IF exist E:\Nirmal\Dns\PSFailed.txt Del E:\Nirmal\Dns\PSFailed.txt

IF exist E:\Nirmal\Dns\PSSuccess.txt Del E:\Nirmal\Dns\PSSuccess.txt

 

Echo Server Name, Up/Down, LOR-New Login, LOR-Old Login, SRM-Login?, SRMSNK Login?, Final Login?, PSEXEc, PSEXEC Remark, OS Version, DNS Servers Configured, Error REMARK-LOR New Login, Error REMARK – LOR Old Login, Error REMARK – SRM Login, Error REMARK – SRMSNKING Login >> Report.csv

REM Echo Server Name, DNS Configuration, >> DnsSrv.csv

 

FOR /F “TOKENS=*” %%a IN (%srvlist%) DO CALL:DONOW “%%a”

 

:DONOW

 

SET srvname=%~1

 

REM Echo %srvname%, >> Dnssrv.csv

 

IF [%OldSrv%] == [] SET OldSrv=%srvname%

 

SET /a totcnt=%totcnt%+1

 

CLS

 

Echo 1.Processing Server: %srvname% Total Server:[%totcnt% Of %totsrv%] Last Server: %OldSrv%

Echo 2.Checking Connectivity……………

 

IF exist E:\Nirmal\Dns\pingresult.txt Del E:\Nirmal\Dns\pingresult.txt

 

Ping -n 1 %srvname% > PingResult.txt 2>&1

 

FIND /i “Reply From” < PingResult.txt > DoNotShow.txt 2>&1

 

IF %errorlevel% == 0 (

 

  SET ServerStat=UP

 

  Echo 3.Reply received from Host %srvname%

  Echo %srvname% >> HostsAlive.txt

 

  REM This is to check wether currently logged in user have access or not.

 

  IF exist E:\Nirmal\Dns\Access.txt Del E:\Nirmal\Dns\Access.txt

  IF exist E:\Nirmal\Dns\NoAccess.txt Del E:\Nirmal\Dns\NoAccess.txt

 

  Echo 4.Checking Access for Currently Logged on user on Server: %srvname%

 

  DIR \\%srvname%\C$ > Access.txt 2>&1

 

  FIND /i “File(s)” < Access.txt > DoNotShow.txt

 

  IF !errorlevel! NEQ 0 (

 

     FOR /F “Tokens=*” %%T In (‘Type Access.txt’) DO SET NewComERR=”%%T”

 

     IF exist E:\Nirmal\Dns\LORold.txt Del E:\Nirmal\Dns\LORold.txt

 

     Echo 5.LOR New login failed…checking LOR Old password

 

     NET USE T: /delete > DoNotShow.txt 2>&1

     NET USE T: \\%srvname%\c$ /user:LORtest password > LOROld.txt 2>&1

    

     FIND /i “The command completed successfully.” < LORold.txt > DoNotShow.txt 2>&1

 

     IF !errorlevel! NEQ 0 (

            

        Echo 6.LOR Old password also failed…

        SET LOR_Old=Failed

        SET LOR_New=Failed

        SET Final_Login=Failed

  

        FOR /F “Tokens=*” %%T In (‘Type LORold.txt’) DO SET ComERR=”%%T”

 

        IF exist E:\Nirmal\Dns\SRMLogin.txt Del E:\Nirmal\Dns\SRMLogin.txt

 

        Echo 5.LOR Old login failed…checking SRM Login

 

        NET USE T: /delete > DoNotShow.txt 2>&1

        NET USE T: \\%srvname%\c$ /user:SRM\nsharma27 Password2006 > SRMLogin.txt 2>&1

    

        FIND /i “The command completed successfully.” < SRMLogin.txt > DoNotShow.txt 2>&1

 

        IF !errorlevel! NEQ 0 (

 

           Echo 7.SRM Login also failed…

 

           SET LOR_Old=Failed

           SET LOR_New=Failed

           SET AMU_Login=Failed    

           SET Final_Login=Failed

    

           FOR /F “Tokens=*” %%T In (‘Type SRMLogin.txt’) DO SET ComERRSRM=”%%T”

 

           IF exist E:\Nirmal\Dns\SNKlogin.txt Del E:\Nirmal\Dns\SNKLogin.txt

 

           Echo 5.SRM Login also failed…checking SRMSNKING Login…

 

           NET USE T: /delete > DoNotShow.txt 2>&1

           NET USE T: \\%srvname%\c$ /user:SRMSNKING\nsharma27 Password2006 > SNKLogin.txt 2>&1

    

           FIND /i “The command completed successfully.” < SNKLogin.txt > DoNotShow.txt 2>&1

 

           IF !errorlevel! NEQ 0 (

      

              Echo 7.SRM Login also failed…

 

              SET LOR_Old=Failed

              SET LOR_New=Failed

              SET AMU_Login=Failed    

              SET SNK_login=Failed

              SET Final_Login=Failed

          

              FOR /F “Tokens=*” %%T In (‘Type SNKLogin.txt’) DO SET ComERRSNK=”%%T”

 

           ) ELSE (

 

              SET ComERRSNK=

              Echo 7.SNKING Login passed…

        

              SET LOR_Old=Failed

              SET LOR_New=Failed

              SET AMU_Login=Failed

              SET SNK_login=Passed

              SET Final_Login=Passed

           )

 

        ) ELSE (

 

           SET ComERRSRM=

           Echo 7.SRM Login passed…

        

           SET LOR_Old=Failed

           SET LOR_New=Failed

           SET AMU_Login=Passed

           SET Final_Login=Passed

        )

 

     ) ELSE (

  

        SET ComERR=

               

        Echo 6.LOR Old password Passed…

        SET LOR_New=Failed

        SET LOR_old=Passed

        SET Final_Login=Passed

     )

 

  ) ELSE (

    

     SET NewComERR=

 

     Echo 5.Currently Logged on user have access…

     Echo 6.LOR New SRMthentication passed…

 

     SET LOR_New=Passed

     SET Final_Login=Passed

     SET LOR_Old=Not Checked

  )     

 

  IF !Final_Login! == Failed (

    

     SET DLS_B=

     SET BIAS_B=

     SET DLS_A=

     SET BIAS_A=

     SET TimeZone_N=

     SET PSEXEC_TZ=

     SET Rem_Req=

     SET AOS_Ver=

     SET AOS_Folder=

     SET AOS_Un=

     SET PSEXEC_SPU=

     SET Uninst_Fold=

     SET Os_SRMto_E=

 

     Echo 5.Login Failed…user DON’T have access to copy DST Folder.

    

     Echo %srvname% >> NoAccess.txt

 

  ) ELSE (

 

     Echo 5.Currently Logged in user have access on C:\ drive.

 

     Echo 6.Check OS Version and Windows System Folder name…

 

     IF exist E:\Nirmal\Dns\Windir.txt Del E:\Nirmal\Dns\Windir.txt

     IF exist E:\Nirmal\Dns\UnFold.txt Del E:\Nirmal\Dns\UnFold.txt

 

     Psexec.exe \\%srvname% cmd.exe /c SET > Windir.txt 2>&1

    

     FIND /i “windir=C:\WINDOWS” < Windir.txt > DoNotShow.txt 2>&1

 

     IF !errorlevel! == 0 (

        

      SET AOS_Ver=”Windows 2003″

        Echo 6.OS Version: !AOS_Ver!

 

     ) ELSE (

       

        SET AOS_Ver=”Windows 2000″

        Echo 6.OS Version: !AOS_Ver! 

 

     )

 

     IF exist E:\Nirmal\Dns\Dns.txt Del E:\Nirmal\Dns\Dns.txt

     IF exist E:\Nirmal\Dns\Othdns.txt Del E:\Nirmal\Dns\Othdns.txt

 

     Psexec.exe \\%srvname% Ipconfig /all > Dns.txt 2>&1

 

     Find /i “DNS Servers” < Dns.txt > Othdns.txt 2>&1

     FOR /F “Tokens=*” %%a IN (Othdns.txt) DO SET DNS_CONF=%%a

  

   

REM FOR /F “Tokens=*” %%a IN (othdns.txt) DO (

 

REM         SET DNS_Conf=

REM       SET DNS_Conf=%%a

REM          Echo ,!DNS_Conf!, >> DnsSrv.csv

        

REM   )

  

 

   )

 

) ELSE (

 

  SET ServerStat=Down

 

  Find /i “Request Timed” < PingResult.txt > DoNotShow.txt

 

  IF !errorlevel! == 0 (

     SET ServerStat=Request Timed Out

  ) ELSE (

     SET ServerStat=Uknown Host

  )

 

  SET LOR_NEW=

  SET LOR_OLD=

  SET DLS_B=

  SET BIAS_B=

  SET DLS_A=

  SET BIAS_A=

  SET TimeZone_N=

  SET PSEXEC_TZ=

  SET Rem_Req=

  SET PSEXEC_SPU=

  SET DST_Stat=

  SET AOS_Ver=

  SET AOS_Folder=

  SET AOS_Un=

  SET Uninst_Fold=

  SET Os_SRMto_E=

  SET DNS_Conf=

  SET DST_Stat=NotOk

  SET Rem_Req=

  SET ComERR=

  SET NewComERR=

  SET PS_Rem=

  SET REG_Use=

  SET Method_U=

  SET REG_Upload=

  SET Copy_Un_F=

  SET DST_Source=

  SET DST_Dest=

  SET Fold_Drive=

  SET Fold_Loc=

  SET Search_C=

  SET Search_D=

  SET Search_E=

  SET AMU_Login=

  SET ComERRSRM=

  SET Int_Logon=

  SET Loc_Power=

  SET SNK_login=

  SET ComERRSNK=

 

  Echo %srvname% >> HostsDown.txt

  Echo 3.Reply NOT received from Host %srvname%

 

)

 

SET OldSrv=%srvname%

 

IF [!srvname!] == [] (

 

  Echo Empty

 

) ELSE (

 

ECHO %srvname%, %ServerStat%, %LOR_NEW%, %LOR_OLD%, %AMU_Login%, %SNK_login%, %Final_Login%, %PSEXEC_TZ%, %PS_Rem%, %AOS_Ver%, %Dns_conf%, %NewComERR%, %ComERR%, %ComERRSRM%, %ComERRSNK%, >> Report.csv

 

  SET ServerStat=Down

  SET Final_login=

  SET LOR_NEW=

  SET Int_Logon=

  SET LOR_OLD=

  SET DLS_B=

  SET BIAS_B=

  SET DLS_A=

  SET BIAS_A=

  SET TimeZone_N=

  SET PSEXEC_TZ=

  SET Rem_Req=

  SET AOS_Ver=

  SET AOS_Folder=

  SET AOS_Un=

  SET Uninst_Fold=

  SET DNS_Conf=

  SET Os_SRMto_E=

  SET DST_Stat=NotOk

  SET Rem_Req=Yes

  SET ComERR=

  SET NewComERR=

  SET PS_Rem=

  SET Method_U=

  SET REG_Use=

  SET REG_Upload=

  SET Copy_Un_F=

  SET DST_Source=

  SET DST_Dest=

  SET Fold_Drive=

  SET Fold_Loc=

  SET Search_C=

  SET Search_D=

  SET Search_E=

  SET AMU_Login=

  SET ComERRSRM=

  SET SNK_login=

  SET ComERRSNK=

  SET Loc_Power=

  

)

 

:eof

 

Leave a Reply

Your email address will not be published. Required fields are marked *