php - Caught exception: Source: SWbemLocator The RPC server is unavailable

440

I have wmi script i will get system info from remote host using wmi some of host are not on and it throw

Caught exception:Source: SWbemLocator Description: The RPC server is unavailable.
Caught exception: Source: SWbemLocator Description: The RPC server is unavailable

$host = array('192.168.8.1','192.168.8.2','192.168.8.3');

foreach ($host as $ip) {
    $user_name = "username/domain";
    $password = "password";

    try {
        $WbemLocator = new COM ("WbemScripting.SWbemLocator");
        $ss = $WbemLocator->ConnectServer($ip, 'root\\cimv2', $user_name, $password);
        $ss->Security_->ImpersonationLevel = 3;
    } catch(Exception $e) {
        echo 'Caught exception: ',  $e->getMessage(), "\n";
    }

    $Win32_ComputerSystem    =    $ss->ExecQuery("Select * from Win32_ComputerSystem"); 

    foreach ( $Win32_ComputerSystem as $ComputerSystem ) {
        $System_Name = $ComputerSystem->Name;
        $System_Domain = $ComputerSystem->Domain ;
        $System_SystemType = $ComputerSystem->SystemType;
        $System_Manufacturer = $ComputerSystem->Manufacturer;
        $System_Model = $ComputerSystem->Model;
    }
    echo $System_Name;
}

If 192.168.8.1 host on it will work well but in loop 192.168.8.2 in not on then it will give Caught exception: Source: SWbemLocator Description: The RPC server is unavailable. Caught exception: Source: SWbemLocator Description: The RPC server is unavailable and break PHP script .. please help

People are also looking for solutions to the problem: php - Laravel helpers loaded twice

Source

Didn't find the answer?

Our community is visited by hundreds of web development professionals every day. Ask your question and get a quick answer for free.

Ask a Question

Write quick answer

Do you know the answer to this question? Write a quick response to it. With your help, we will make our community stronger.

Similar questions

Find the answer in similar questions on our website.