获取Windows Cluster IP的VBS脚本和命令(无powershell)


strComputer = "." 
Set objWMIService = GetObject("winmgmts:" _ 
    & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2") 
 
Set IPConfigSet = objWMIService.ExecQuery _ 
    ("Select * from Win32_NetworkAdapterConfiguration Where IPEnabled=TRUE") 
  
For Each IPConfig in IPConfigSet 
    If Not IsNull(IPConfig.IPAddress) Then  
        For i=LBound(IPConfig.IPAddress) to UBound(IPConfig.IPAddress) 
            WScript.Echo IPConfig.IPAddress(i) 
        Next 
    End If 
Next



用这个命令也行:nbtstat -a <cluster name>

cluster res "Cluster IP Address" /priv



/

vector<wstring> GetCoreClusterIPAddresses()
{
    vector<wstring> coreIPAddresses;
    wstring coreGroup = GetCoreClusterGroup();
    HCLUSTER hCluster = OpenCluster(NULL);
    if(hCluster)
    {
        HGROUP hCoreGroup = OpenClusterGroup(hCluster, coreGroup.c_str());
        if(hCoreGroup)
        {
            DWORD index = 0, type = 0, nameSize = MAX_PATH;
            wstring resourceName;
            resourceName.resize(MAX_PATH);
            HGROUPENUM hGroupEnum = ClusterGroupOpenEnum(hCoreGroup, CLUSTER_GROUP_ENUM_CONTAINS);
            if(hGroupEnum)
            {
                DWORD status = ClusterGroupEnum(hGroupEnum, index, &type, &resourceName[0], &nameSize);
                while(ERROR_SUCCESS == status)
                {
                    HRESOURCE hResource = OpenClusterResource(hCluster, &resourceName[0]);
                    
                    if(hResource)
                    {
                        wstring resourceType;
                        resourceType.resize(MAX_PATH);
                        DWORD resourceTypeSize = MAX_PATH;
                        
                        if(ERROR_SUCCESS == ClusterResourceControl(hResource, NULL, CLUSCTL_RESOURCE_GET_RESOURCE_TYPE, NULL, NULL, &resourceType[0], MAX_PATH, &resourceTypeSize))
                        {
                            if(_wcsicmp (resourceType.c_str(), L"IP Address") == 0 || _wcsicmp (resourceType.c_str(), L"IPv6 Address") == 0 )
                            {
                                wstring privProperties;
                                privProperties.resize(4096);
                                DWORD propSize;
                                if(ERROR_SUCCESS == ClusterResourceControl(hResource, NULL, CLUSCTL_RESOURCE_GET_PRIVATE_PROPERTIES, NULL, NULL, &privProperties[0], 4096, &propSize))
                                {
                                    LPWSTR pPropValue = 0; 
                                    ResUtilFindSzProperty(&privProperties[0], propSize, L"Address", &pPropValue);
                                    coreIPAddresses.push_back(pPropValue);
                                    if(pPropValue)
                                        LocalFree(pPropValue);
                                }
                            }                          
                        }
                        CloseClusterResource(hResource);
                    }
                    index++;
                    nameSize = MAX_PATH;
                    resourceName.resize(MAX_PATH);
                    status = ClusterGroupEnum(hGroupEnum, index, &type, &resourceName[0], &nameSize);
                }
                ClusterGroupCloseEnum(hGroupEnum);
            }
            CloseClusterGroup(hCoreGroup);
        }
        CloseCluster(hCluster);
    }
    return coreIPAddresses;
}
wstring GetCoreClusterGroup()
{
    wstring coreGroup;
    HCLUSTER hCluster = OpenCluster(NULL);
    if(hCluster)
    {
        HRESOURCE hClusterName = NULL, hClusterIPAddress = NULL, hClusterQuorum = NULL;
        if(ERROR_SUCCESS == ResUtilGetCoreClusterResources(hCluster, &hClusterName, &hClusterIPAddress, &hClusterQuorum))
        {
           coreGroup.resize(MAX_PATH);
           DWORD groupSize = MAX_PATH;
           
           GetClusterResourceState(hClusterName, NULL, NULL, &coreGroup[0], &groupSize);
         
            if(hClusterName)
                CloseClusterResource(hClusterName);
            if(hClusterIPAddress)
                CloseClusterResource(hClusterIPAddress);
            if(hClusterQuorum)
                CloseClusterResource(hClusterQuorum);
        }
        CloseCluster(hCluster);
    }
    
    return coreGroup;
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值