推荐

win下php获取cpu序列号硬盘序列号-原创

2016-05-23 15:48
<?php
/**
 * 获取cpu序列号
 */
function getCpuId(){
    $uuid = '';
    exec("wmic CPU get ProcessorID", $result);
    $uuid = $result[1];
    return $uuid;
}

/**
 * 获取硬盘序列号(第一个硬盘)
 */
function getDiskId(){
    $uuid = '';
    $bat = dirname(__FILE__) . '/'. time() . rand(11111,99999) . rand(11111,99999) . '.bat';
    file_put_contents($bat, "select disk 0 \n detail disk");
    exec("diskpart /s " . realpath($bat) , $result);
    unlink($bat);
    foreach ($result as $key => $value) {
        if (strpos($value, 'ID:')!==false) {
            $uuid = trim(substr($value, (strpos($value, 'ID:') + 3)));
        }
    }
    return $uuid;
}

echo getCpuId();
echo '***';
echo getDiskId();
exit();


^