vbs获取IP地址

 

Set WshNetwork = WScript.CreateObject("WScript.Network")
cName = WshNetwork.ComputerName '取本机计算机名
Const ForAppending = 8
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objTextFile = objFSO.OpenTextFile("" & cName & ".txt",ForAppending,True)
objTextFile.Write("计算机名:"&cName&",")
objTextFile.Write("IP:"&GetIP(".")&",")
objTextFile.Write(formatdatetime(now,1)&",")
objTextFile.Write(time&",")
objTextFile.Close

Function GetIP(ComputerName) '取本机IP
Dim objWMIService,colItems,objItem,objAddress
Set objWMIService = GetObject("winmgmts:\\" & ComputerName & "\root\cimv2")
Set colItems = objWMIService.ExecQuery("Select * From Win32_NetworkAdapterConfiguration Where IPEnabled = True")
For Each objItem in colItems
    For Each objAddress in objItem.IPAddress
        If objAddress <> "" then
            GetIP = objAddress
            Exit For
        End If
    Next
Next
End Function

你可能感兴趣的:(VBS)