我創建了一個vbscript來從服務器獲取一堆系統信息,並且我需要獲得的一件事是服務器的IP地址。顯然,我只是得到了「心跳ip地址」,這不是我需要的。如何獲得Windows 2008服務器中的羣集的IP地址
有沒有一種方式與vbscript爲我配合wmi並獲得ip地址,我假設的私人地址。
我想這WMI類 http://msdn.microsoft.com/en-us/library/windows/desktop/aa371441(v=vs.85).aspx
這裏是我有什麼
Option Explicit
'On Error Resume Next
Dim strIPAddress,objItem,colItems,objWMISrvc,strComputer,objAddr
strComputer = "."
Set objWMISrvc = GetObject("winmgmts:{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
getIPAddress
Sub getIPAddress()
'Check if system is a cluster'
strIPAddress = ""
Set colItems = objWMISrvc.ExecQuery("SELECT * FROM MSCluster_Network")
If Err.Number <> 0 Then
For Each objItem in colItems
'strIPAddress = "IP Address: " & objItem.
For i = 0 to UBound(objItem.IPv4Addresses)
strIPAddress = "IP Address (" & i & "): " & objItem.IPv4Addresses(i)
Next
Next
End If
'############################################################
' These are all commented because this is how I WAS getting
' the ip address but it only returned the heartbeat.
' I will still be using this if I can somehow tell if a server is a cluster or not.
'If strIPAddress = "" Then
'' Dim i
'' Set colItems = objWMISrvc.ExecQuery("SELECT * FROM Win32_NetworkAdapterConfiguration")
'For Each objItem in colItems
'' If Not IsNull(objItem.IPAddress) Then
'' strIPAddress = objItem.IPAddress(0)
'' 'For i = 0 to UBound(objItem.IPAddress)
'' ' ' strIPAddress = strIPAddress & " | " & objItem.IPAddress(i)
'' Next
'' End If
'Next
'End If
WScript.Echo strIPAddress
End Sub
當我的客戶跑這了羣集服務器上,它提供了一個空的msgbox,所以也沒拉的IP地址。
我不知道爲什麼我一直downvoted ... =/ – envinyater 2013-02-26 20:32:22