Jump to content

PHP and WMI - querying for IP addresses on remote hosts


ryamigo

Recommended Posts

Hello,

 

I'm attempting to write a PHP script to query WMI for an IP address of a host. The reason I'm doing this instead of getbyhostname is because NAT translations on the network can cause inaccurate results. The question is two-fold:

 

1) My Script is as follows

<?

$obj = new COM ( 'winmgmts://localhost/root/CIMV2' );
$wmi_network = $obj->ExecQuery("Select * From Win32_NetworkAdapterConfiguration");

foreach ( $wmi_network as $wmi_call )
{
    $ipaddr = $wmi_call->IPAddress;
    echo $ipaddr;
}
?>

 

I get the following error when running the script:

Catchable fatal error: Object of class variant could not be converted to string

 

 

2) How do I go about querying a remote host on the network with valid credentials?

 

 

Thank you

Link to comment
Share on other sites

you can't do it with PHP, it is run purely server side, you would need javascript or possably ajax. 

 

Although I can't think of a single legal reason you could have to be trying to obtain this information without simply enquiering from the person using the computer that you want the local IP address of.

 

P.S. Bumping posts is against the rules.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.