取得磁碟機序號

回覆文章
yehlu
Site Admin
文章: 3245
註冊時間: 2004-04-15 17:20:21
來自: CodeCharge Support Engineer

取得磁碟機序號

文章 yehlu »

代碼: 選擇全部

switch (PHP_OS) {
    case ('Darwin'):
        exec('ioreg -rd1 -w0 -c AppleAHCIDiskDriver | grep Serial', $res);
        $sna = explode('=', $res[0]);
        foreach ($sna as $key => $value) {
            $value = str_replace('"', '', $value);
            if (trim($value) != 'Serial Number') {
                $sn[] = trim($value);
            }
        }
        break;
    case ('Linux'):
        exec('lsblk --nodeps -no name,serial', $res);
        foreach ($res as $key => $value) {
            $sn[] = substr($value, 5);
        }        
        break;
    case ('WINNT');
        exec('wmic path win32_physicalmedia get Tag,SerialNumber', $res);
        foreach ($res as $key => $value) {
            $data = explode("\\", $value);
            if (count($data) > 1) {
                if ($data['0'] != '') {
                    $sn[] = $data['0'];
                }
            }
        }
        break;
    default:
}
回覆文章

回到「PHP」