'========================================================================== ' NAME: DNS Lookup ' AUTHOR: Marcus Oh ' DATE : 5/13/2006 ' COMMENT: Returns 'error' if nslookup fails. '========================================================================== ' Standard Event Type Numeric Values Const EVENT_TYPE_SUCCESS = 0 Const EVENT_TYPE_ERROR = 1 Const EVENT_TYPE_WARNING = 2 Const EVENT_TYPE_INFORMATION = 4 Set oShell = CreateObject("Wscript.Shell") sHosts = ScriptContext.Parameters.Get("HostNames") bLogSuccessEvent = CBool(ScriptContext.Parameters.Get("LogSuccessEvent")) If Len(sHosts)> 0 Then If InStr(sHosts,",") <> 0 Then iNames = Instr(sHosts, ",") Do While iNames > 0 DNSlookup(Trim(Left(sHosts, iNames - 1))) sHosts = Mid(sHosts,iNames + 1) iNames = InStr(sHosts,",") If iNames = 0 Then DNSlookup(Trim(sHosts)) End If Loop Else DNSlookup(Trim(sHosts)) End If Else CreateEvent 41000,EVENT_TYPE_INFORMATION,"DNS Synthetic Script","No host names defined." End If Function DNSlookup(sHost) sCommand = "%ComSpec% /c nslookup " & sHost Set oShellRun = oShell.Exec(sCommand) Proceed = 0 Do Until oShellRun.StdOut.AtEndOfStream sLine = Trim(oShellRun.StdOut.ReadLine) NameTag = LCase(Left(sLine,5)) Select Case NameTag Case "name:" Proceed = 1 End Select If Proceed = 1 Then sData = Trim(Mid(sLine,6)) aLine = Split(sLine, ":") sData = Trim(aLine(1)) Exit Do End If Loop If Proceed = 0 Then CreateEvent 41001,EVENT_TYPE_ERROR,"DNS Synthetic Script","Lookup failed for " & sHost & "." End If If Lcase(TypeName(sData)) <> LCase("Empty") and bLogSuccessEvent Then CreateEvent 41002,EVENT_TYPE_INFORMATION,"DNS Synthetic Script","Successfully looked up " & sHost & "." End If End Function ' Standard Event creation subroutine Sub CreateEvent(iEventNumber,iEventType,sEventSource,sEventMessage) Set oEvent = ScriptContext.CreateEvent() oEvent.EventNumber = iEventNumber oEvent.EventType = iEventType oEvent.EventSource = sEventSource oEvent.Message = sEventMessage ScriptContext.Submit oEvent End Sub