"indytoatl" <indytoatl@xxxxxx> wrote in message
news:a2a96951-aa65-4acb-9650-f6115232580f@xxxxxx
> I'm trying to convert a list of servers names from hostnames to IP
> addresses. Can someone tell
> me whats wrong with my script? thanks
>
>
> Const FOR_READING = 1
> Const FOR_APPENDING = 8
>
>
> Dim WshShell, objInputFile, objOutputFile
> Dim objNetwork, IP
> Dim RegEx, WSH, strTarget, arrTargets
>
> Set RegEx = New RegExp
>
> Set WSH = CreateObject("WScript.Shell")
> Set WshShell = WScript.CreateObject("WScript.Shell")
> Set FileSys = CreateObject("Scripting.FileSystemObject")
> Set objNetwork = WScript.CreateObject("WScript.Network")
>
>
>
> Set objInputFile = FileSys.OpenTextFile("c:\hostnames.txt",
> For_Reading)
> Set objOutputFile = FileSys.CreateTextFile("c:\IP.txt", For_Appending)
>
> arrServers = (objInputFile.ReadAll)
> arrTargets = Split(arrServers, vbTab)
> objInputFile.Close
>
>
>
> 'WScript.Echo arrTargets(0)
>
> For Each strTarget In arrTargets
>
> Set oExec = WSH.Exec("ping.exe -n 2 " & strTarget)
> RegEx.Pattern = "^Reply from ([^:]+).*$"
>
>
> Do Until oExec.Status = 0
> WScript.Sleep 100
> Loop
>
> Do Until oExec.StdOut.AtEndOfStream
> Line = oExec.StdOut.ReadLine
> If RegEx.Test(Line) Then IP = RegEx.Replace(Line, "$1")
> Loop
>
> WScript.Echo IP
> objOutputFile.WriteLine IP
>
> Next The script works for me except:
1. I cannot write to the root of C: drive on my Vista computer. I assume the
same is true of W2k8 and Win7. I believe this can be corrected by using "Run
as administrator".
2. My firewall requires that I acknowledge all ping requests, so that
blocked the script.
3. I could not get the script to read a tab delimited file correctly.
When I run the script on a W2k3 client with no firewall in my test domain it
worked, after I wrote one computer name per line in the file hostnames.txt
and changed:
arrTargets = Split(arrServers, vbTab)
to:
arrTargets = Split(arrServers, vbCrLf)
However, the IP address for the last computer was listed twice until I added
a check for blank lines to the script. That is, I used:
For Each strTarget In arrTargets
If (Trim(strTarget) <> "") Then
.....
End If
Next
If you get an error, what is it?
--
Richard Mueller
MVP Directory Services
Hilltop Lab -
http://www.rlmueller.net
--