Get DNS Server info via VBScript
Intr-o retea cu multe servere DNS, si de regula acolo unde sunt multe DC-uri sunt si multe DNS-uri poate o exista o problema in standardizarea setarilor pe aceste servere. Si cum DNS-ul reprezinta una din principalele cauze pentru care din cand in cand lucrurile nu merg asa cum ar trebui m-am gandit sa fac un script care sa se conecteze la toate DC-urile din domeniu si sa afiseze setarile serverului de DNS.
In cazul meu ma interesau setarile ce tin de forwarder, dar hai sa vedem ce a iesit.
Prima data trebuie sa aflam care sunt serverele DC din domeniu. Pentru asta m-am inspirat dintr-un script de-al lui Richard Mueller care se conecteaza la configuration partion si cauta toate obiectele de tip NTDSA. Problema e ca noi trebuie sa cautam doar DC-urile, altfel as fi cautat simplu dupa server, dar e posibil gasesc si ceva servere Exchange care mai apar pe acolo. Cautand dupa NTDSA gasesc DC-urile insa trebuie sa aflu obiectul parinte, de asta am apelat la scriptul lui Richard Mueller ca sa nu ma mai chinui eu. Bineinteles ca exista si alte variante – gen enumerarea obiectelor din containerul Domain Controllers.
Dim objRootDSE, strConfig, adoConnection, adoCommand, strQuery
Dim adoRecordset, objDC, objSite
‘ Determine configuration context from RootDSE object.
Set objRootDSE = GetObject("LDAP://RootDSE")
strConfig = objRootDSE.Get("configurationNamingContext")
‘ Use ADO to search Active Directory for ObjectClass nTDSDSA.
Set adoCommand = CreateObject("ADODB.Command")
Set adoConnection = CreateObject("ADODB.Connection")
adoConnection.Provider = "ADsDSOObject"
adoConnection.Open "Active Directory Provider"
adoCommand.ActiveConnection = adoConnection
strQuery = "<LDAP://" & strConfig _
& ">;(ObjectClass=nTDSDSA);AdsPath;subtree"
adoCommand.CommandText = strQuery
adoCommand.Properties("Page Size") = 100
adoCommand.Properties("Timeout") = 30
adoCommand.Properties("Cache Results") = False
Set adoRecordset = adoCommand.Execute
‘ The parent object of each object with ObjectClass=nTDSDSA is a Domain
‘ Controller. The parent of each Domain Controller is a "Servers"
‘ container, and the parent of this container is the "Site" container.
Do Until adoRecordset.EOF
Set objDC = GetObject( _
GetObject(adoRecordset.Fields("AdsPath").Value).Parent)
Set objSite = GetObject(GetObject(objDC.Parent).Parent)
Wscript.Echo "Domain Controller: " & objDC.cn & vbCrLf _
& "DNS Host Name: " & objDC.DNSHostName & vbCrLf _
& "Site: " & objSite.name
‘Aici e bucata de cod care se conecteaza la DNS si citeste proprietatile
strComputer = objDC.cn
Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\\" & strComputer & _
"\root\MicrosoftDNS")
Set colItems = objWMIService.ExecQuery("Select * from MicrosoftDNS_Server")
For Each objItem in colItems
Wscript.Echo "Address Answer Limit: " & objItem.AddressAnswerLimit
Wscript.Echo "Allow Update: " & objItem.AllowUpdate
Wscript.Echo "Autocache Update: " & objItem.AutoCacheUpdate
Wscript.Echo "Autoconfig File Zones: " & objItem.AutoConfigFileZones
Wscript.Echo "Bind Secondaries: " & objItem.BindSecondaries
Wscript.Echo "Boot Method: " & objItem.BootMethod
Wscript.Echo "Default Aging State: " & objItem.DefaultAgingState
Wscript.Echo "Default No-Refresh Interval: " & _
objItem.DefaultNoRefreshInterval
Wscript.Echo "Default Refresh Interval: " & objItem.DefaultRefreshInterval
Wscript.Echo "Disable AutoReverse Zones: " & _
objItem.DisableAutoReverseZones
Wscript.Echo "Disjoint Nets: " & objItem.DisjointNets
Wscript.Echo "Directory Service Available: " & objItem.DsAvailable
Wscript.Echo "Directory Service Polling Interval: " & _
objItem.DsPollingInterval
Wscript.Echo "Directory Service Tombstone Interval: " & _
objItem.DsTombstoneInterval
Wscript.Echo "EDNS Cache Timeout: " & objItem.EDnsCacheTimeout
Wscript.Echo "Enable Directory Partitions: " & _
objItem.EnableDirectoryPartitions
Wscript.Echo "Enable DNSSec: " & objItem.EnableDnsSec
Wscript.Echo "Enable EDNS Probes: " & objItem.EnableEDnsProbes
Wscript.Echo "Event Log Level: " & objItem.EventLogLevel
Wscript.Echo "Forward Delegations: " & objItem.ForwardDelegations
If Not IsNull(objItem.Forwarders) Then
strForwarders = Join(objItem.Forwarders, ",")
Wscript.Echo "Forwarders: " & strForwarders
Else
Wscript.Echo "Forwarders:"
End If
Wscript.Echo "Forwarding Timeout: " & objItem.ForwardingTimeout
Wscript.Echo "Is Slave: " & objItem.IsSlave
If Not IsNull(objItem.ListenAddresses) Then
strListenAddresses = Join(objItem.ListenAddresses, ",")
Wscript.Echo "Listen Addresses: " & strListenAddresses
Else
Wscript.Echo "Listen Addresses:"
End If
Wscript.Echo "Local Net Priority: " & objItem.LocalNetPriority
Wscript.Echo "Logfile Maximum Size: " & objItem.LogFileMaxSize
Wscript.Echo "Logfile Path: " & objItem.LogFilePath
If Not IsNull(objItem.LogIPFilterList) Then
strIPFilter = Join(objItem.LogIPFilterList, ",")
Wscript.Echo "Log IPFilter List: " & strIPFilter
Else
Wscript.Echo "Log IPFilter List:"
End If
Wscript.Echo "Log Level: " & objItem.LogLevel
Wscript.Echo "Loose Wildcarding: " & objItem.LooseWildcarding
Wscript.Echo "Maximum Cache Time-to-Live: " & objItem.MaxCacheTTL
Wscript.Echo "Maximum Negative Cache Time-to-Live: " & _
objItem.MaxNegativeCacheTTL
Wscript.Echo "Name Check Flag: " & objItem.NameCheckFlag
Wscript.Echo "No Recursion: " & objItem.NoRecursion
Wscript.Echo "Recursion Retry: " & objItem.RecursionRetry
Wscript.Echo "Recursion Timeout: " & objItem.RecursionTimeout
Wscript.Echo "RoundRobin: " & objItem.RoundRobin
Wscript.Echo "Rpc Protocol: " & objItem.RpcProtocol
Wscript.Echo "Scavenging Interval: " & objItem.ScavengingInterval
Wscript.Echo "Secure Responses: " & objItem.SecureResponses
Wscript.Echo "Send Port: " & objItem.SendPort
If Not IsNull(objItem.ServerAddresses) Then
strServerAddress = Join(objItem.ServerAddresses, ",")
Wscript.Echo "Server Addresses: " & strServerAddress
Else
Wscript.Echo "Server Addresses:"
End If
Wscript.Echo "Started: " & objItem.Started
Wscript.Echo "Start Mode: " & objItem.StartMode
Wscript.Echo "Strict File Parsing: " & objItem.StrictFileParsing
Wscript.Echo "Update Options: " & objItem.UpdateOptions
Wscript.Echo "Version: " & objItem.Version
Wscript.Echo "Write Authority NS: " & objItem.WriteAuthorityNS
Wscript.Echo "Xfr Connect Timeout: " & objItem.XfrConnectTimeout
Wscript.Echo "———————————————————-"
Next
adoRecordset.MoveNext
Loop
adoRecordset.Close
Richard merge pe varianta cu Option Explicit de asta exista liniile cu Dim, insa a trebuit sa dezactivez asta pentru ca in bucata mea de cod nu am declarat variabilele. Am lasat si commenturile lui pentru a fi ceva mai inteligibil scriptul.
Daca va intereseaza doar “forwarders” puteti sa da-ti remove la restul liniilor de cod.