Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Get IP address from text file

Status
Not open for further replies.

youngso

Technical User
Nov 17, 2009
2
'This read the text file and validate the ip address before it put's on the log file.

Set objFSO = CreateObject("Scripting.FileSystemObject")
Const ForReading = 1, ForWriting = 2, ForAppending = 8

ReadFile "c:\scripts\machinelist.txt"


'This subroutine read the contain and writes to another file
Sub ReadFile(strdirfile)
Dim strLine, i, objTextFile

Set objTextFile = objFSO.OpenTextFile(strdirfile, _
ForReading)

Do While objTextFile.AtEndOfStream <> True

strLine = objtextFile.ReadLine
'strLine = LCase(strLine)


'If inStr(strLine, Errmsg) Then
'WriteLog (strLine)
ComputerName = strLine
ResolveIP computername

i = i + 1
'End If
Loop



End Sub

Sub WriteLog (ByRef String)
Dim sIssueLog, UserArcSetFile

sLogPath = objFSO.BuildPath("c:\scripts","ipaddress.log")


If objFSO.FileExists (sLogPath) Then
Set UserArcSetFile = objFSO.OpenTextFile(sLogPath, ForAppending, False)
UserArcSetFile.WriteLine (String)
UserArcSetFile.Close
else
Set UserArcSetFile = objFSO.CreateTextFile(sLogPath, True)
UserArcSetFile.WriteLine (String)
UserArcSetFile.Close
End If

End Sub

Function ResolveIP(strComputer)
Dim wmiQuery : wmiQuery = "Select * From Win32_PingStatus Where Address = '" & strComputer & "'"

Dim objWMIService : Set objWMIService = GetObject("winmgmts:\\.\root\cimv2")
Dim objPing : Set objPing = objWMIService.ExecQuery(wmiQuery)
Dim objStatus
ResolveIP = "Computer is Unreachable!"
For Each objStatus In objPing
If objStatus.Statuscode = 0 Then ResolveIP = objStatus.ProtocolAddress
WriteLog ResolveIP
Next
End Function

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top