使用PHP从WMI查询中检索IP地址

时间:2013-02-15 21:25:23

标签: php windows wmi

我正在尝试获取一个脚本,用于检索网络上远程主机的NIC卡信息。

这是我的疑问:

$wmi_networkadapter = $obj->ExecQuery("Select * from Win32_NetworkAdapter WHERE NetConnectionID LIKE 'Local Area Connection'");

这是输出:

   foreach ($wmi_networkadapter as $wmi_call) {
        //Caption
        $Caption = $wmi_call->Caption;
        echo "<b>Caption:</b> $Caption<br>";

        //MACAddress
        $MACAddress = $wmi_call->MACAddress;
        echo "<b>MACAddress:</b> $MACAddress df<br>";                                       
    }

我可以获得Macaddress和Caption(NIC的名称),但我无法弄清楚如何获取IP地址。谢谢!

2 个答案:

答案 0 :(得分:0)

我没有任何专门使用WMI的经验,但是在致电var_dump($wmi_call)时会得到什么结果?

答案 1 :(得分:0)

确定。我能够获得IP地址。

使用此查询:

$wmi_networkadapter = $obj->ExecQuery("Select * from Win32_NetworkAdapterConfiguration WHERE IPENabled = 'True'");

PHP:

foreach ($wmi_networkadapter as $wmi_call) {
    //Caption
    $Caption = $wmi_call->Caption;
    echo "<b>Caption:</b> $Caption<br>";

    //MACAddress
    $MACAddress = $wmi_call->MACAddress;
    echo "<b>MACAddress:</b> $MACAddress<br>";      

    //IP ADDRESS
    $ip = $wmi_call->IPAddress;
    foreach ($ip as $key => $value) {
     echo $value;
    }
}