Hallo Board,
ich habe zwar einen Tag und viel Google, plus kurz mal nen Kollegen gebraucht. Nun ist es aber vollbracht!!
So sollte es klappen!!
Dim Domain
Dim SourceFile
Dim TargetFile
strDomain = ".Domain.local"
strSourceFile = "c:\script\names.txt"
strTargetFile = "c:\script\IPs.txt"
Const ForReading = 1
Const ForWriting = 2
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objTextFile = objFSO.OpenTextFile _
(strSourceFile, ForReading)
Set objLogFile = objFSO.OpenTextFile _
(strTargetFile, ForWriting, True)
Do Until objTextFile.AtEndOfStream
strServerName = objTextFile.Readline
WScript.Echo strServerName & " " & NSlookup (strServerName & strDomain)
objLogFile.WriteLine strServerName & " " & NSlookup (strServerName & strDomain)
Loop
objTextFile.Close()
objLogFile.Close()
Function NSlookup(sHost)
' Both IP address and DNS name is allowed
' Function will return the opposite
Set oRE = New RegExp
oRE.Pattern = "^[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}$"
bInpIP = False
If oRE.Test(sHost) Then
bInpIP = True
End If
Set oShell = CreateObject("Wscript.Shell")
Set oFS = CreateObject("Scripting.FileSystemObject")
sTemp = oShell.ExpandEnvironmentStrings("%TEMP%")
sTempFile = sTemp & "\" & oFS.GetTempName
'Run NSLookup via Command Prompt
'Dump results into a temp text file
oShell.Run "%ComSpec% /c nslookup.exe " & sHost _
& " >" & sTempFile, 0, True
'Open the temp Text File and Read out the Data
Set oTF = oFS.OpenTextFile(sTempFile)
'Parse the text file
Do While Not oTF.AtEndOfStream
sLine = Trim(oTF.Readline)
If LCase(Left(sLine, 5)) = "name:" Then
sData = Trim(Mid(sLine, 6))
If Not bInpIP Then
'Next line will be IP address(es)
'Line can be prefixed with "Address:" or "Addresses":
aLine = Split(oTF.Readline, ":")
sData = Trim(aLine(1))
End If
Exit Do
End If
Loop
'Close it
oTF.Close
'Delete It
oFS.DeleteFile sTempFile
If LCase(TypeName(sData)) = LCase("Empty") Then
NSlookup = ""
Else
NSlookup = sData
End If
End Function