![]() |
![]() | ![]() | ![]() | ![]() | ![]() | ![]() | ![]() |
| Welcome to Windows Vista Forums. Our forum is dedicated to helping you find solutions with any problems, errors or issues you are experiencing with Windows Vista. The Vista forum also covers news and updates and has an extensive Windows Vista tutorial section that covers a wide range of tips and tricks. |
| |||||||
![]() |
| |
| | #1 (permalink) |
| | Convert hostname text file to IP text file 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 |
My System Specs![]() |
| | #2 (permalink) |
| | Re: Convert hostname text file to IP text file "indytoatl" <indytoatl@xxxxxx> wrote in message news:a2a96951-aa65-4acb-9650-f6115232580f@xxxxxx Quote: > 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 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 -- |
My System Specs![]() |
![]() |
| Thread Tools | |
| |
Similar Threads | ||||
| Thread | Forum | |||
| Append text to top of text file? | PowerShell | |||
| Read a line from a text file, without loading the entire file inmemory | PowerShell | |||
| Looping Through A Text File To Find Patterns From Another Text Fil | PowerShell | |||
| Howto: Add lines of text from a specific point in a text file.. | VB Script | |||
| How do I read a text file and sort text by fixed positions? | PowerShell | |||