Skip to content

Commit

Permalink
Added some sanity checks to remove any errors wmic might produce, yet…
Browse files Browse the repository at this point in the history
… still work
  • Loading branch information
grilled-cheese committed Oct 15, 2014
1 parent ded3d42 commit f1c1d79
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions wmi.netstats.php
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,28 @@ function wmic_call($in_host, $in_cred, $in_class, $in_namespace, $in_columns, $i
echo "WMI Client Output: " . implode("\n", $wmiout) . "\n";
exit($execstatus);
}
// Chomp any errors that wmic might have thrown, but still worked
$classindex = -1;
for($i=0;$i<count($wmiout);$i++)
{
if(0 === strpos($wmiout[$i], 'CLASS: '))
{
$classindex = $i;
break;
}
}
// Abort is the wmi output isn't normally structured
if($classindex == -1)
{
echo "WMI Class Chomp Failed!\nWMI Client Output: ".implode("\n", $wmiout)."\n";
exit(1);
}
for($i=0;$i<$classindex;$i++)
{
unset($wmiout[$i]);
}
// reindex the array output
$wmiout = array_values($wmiout);

$wmi_count = count($wmiout); // count the number of lines returned from wmic, saves recouting later
$names = explode('|',$wmiout[1]); // build the names list to dymanically output it
Expand Down

0 comments on commit f1c1d79

Please sign in to comment.