php 讀取windows 的系統版本,硬盤,內存,網卡,數據流量等

php 讀取windows 的系統版本,硬盤,內存,網卡,數據流量等php

 

<?php
header("Content-type: text/html; charset=utf-8");
echo "<pre>\r\n\r\n";

# 系統名稱、版本和類型
$out = '';
$info = exec('wmic os get Caption,Version,OSArchitecture',$out,$status);
$osinfo_array = explode('  ',$out[1]);
$osinfo = array_values(array_filter($osinfo_array));
echo "系統名稱: " . $osinfo[0] ."\r\n系統版本: " . $osinfo[2] ."\r\n系統類型: " . $osinfo[1] ."\r\n\r\n";

# 系統配置
$out = '';
$info = exec('wmic os get producttype',$out,$status);   #返回 3 是server ,返回其它的是 workstation
if($out[1] == 3) $osconfig = "Server";
else $osconfig = "Workstatio";
echo "系統配置: " . $osconfig . "\r\n\r\n";

# 已運行時長
$out = '';
$info = exec('wmic os get lastBootUpTime,LocalDateTime',$out,$status);
$datetime_array = explode('.',$out[1]);
$dt_array = explode(' ',$datetime_array[1]);
$localtime = substr($datetime_array[1],-14);
$boottime = $datetime_array[0];
$uptime = strtotime($localtime) - strtotime($datetime_array[0]);

$day=floor(($uptime)/86400);
$hour=floor(($uptime)%86400/3600);
$minute=floor(($uptime)%86400/60);
$second=floor(($uptime)%86400%60);
echo "已運行: ".$day."天".$hour."小時".$minute."分鐘".$second."秒\r\n\r\n";

# 硬盤用量
$out = '';
$info = exec('wmic logicaldisk get FreeSpace,size /format:list',$out,$status);
$hd = '';
foreach($out as $vaule){
	$hd .= $vaule . ' ';;
}
$hd_array = explode('   ', trim($hd));
$key = 'CDEFGHIJKLMNOPQRSTUVWXYZ';
foreach($hd_array as $k => $v){
	$s_array = explode('Size=', $v);
	$fs_array = explode('FreeSpace=', $s_array[0]);
	$size = round(trim($s_array[1])/(1024*1024*1024), 1);
	$freespace = round(trim($fs_array[1])/(1024*1024*1024), 1);
	$drive = $key[$k];
	echo $drive . "盤,\r\n已用空間: " . ($size - $freespace) . "GB/" . $size . "GB\r\n可用空間: " . $freespace . "GB\r\n\r\n";
}

# 物理內存
$out = '';
$info = exec('wmic os get TotalVisibleMemorySize,FreePhysicalMemory',$out,$status);
# 多個空格轉爲一個空格
$phymem = preg_replace ( "/\s(?=\s)/","\\1",$out[1]);
$phymem_array = explode(' ',$phymem);
//print_r($phymem_array);
$freephymem = ceil($phymem_array[0]/1024);
$totalphymem = ceil($phymem_array[1]/1024);
echo "已用物理內存: ". ($totalphymem - $freephymem) ."MB/". $totalphymem . "MB\r\n空閒物理內存: " . $freephymem . "MB\r\n\r\n";

# 虛擬內存
$out = '';
$info = exec('wmic os get SizeStoredInPagingFiles,FreeSpaceInPagingFiles',$out,$status);
$pagemem = preg_replace ( "/\s(?=\s)/","\\1",$out[1]);
$pagemem_array = explode(' ',$pagemem);
$freepagemem = ceil($pagemem_array[0]/1024);
$totalpagemem = ceil($pagemem_array[1]/1024);
echo "已用虛擬內存: ". ($totalpagemem - $freepagemem) ."MB/". $totalpagemem . "MB\r\n空閒虛擬內存: " . $freepagemem . "MB\r\n\r\n";

# 網卡名稱
$out = '';
$info = exec('wmic nic list brief',$out,$status);
$nic_array = explode('  ', $out[2], 2);
$nic = $nic_array[0];
echo "當前網卡名稱: " . $nic . "\r\n\r\n";

# 網卡流量,最初計量爲字節
$out = '';
$info = exec('netstat -e',$out,$status);
$out_array = array();
foreach ($out as $key => $value) {
    $out_array[$key] = mb_convert_encoding ($value, 'utf-8', 'GBK');
}
$net = preg_replace ( "/\s(?=\s)/","\\1",$out_array[4]);
$net_array = explode(' ',$net);
echo "當前數據流量\r\n已接收: " .round($net_array[1]/(1024*1024), 3) . "MB\r\n已發送: " . round($net_array[2]/(1024*1024), 3) . "MB\r\n\r\n";

//$out = '';
//$info = exec('wmic os get /all  /format:list',$out,$status);
//print_r($out);

# 電腦信息
//$out = '';
//$info = exec('systeminfo',$out,$status);
//print_r($out);

//$info = exec('ipconfig',$out,$status);
//print_r($out);
//$out = '';

# 執行批處理,須要絕對路徑
//$info = exec('C:/Users/Administrator/Downloads/www/mem.bat',$out,$status);
//print_r($out);

//$out = '';
//$info = exec('net statistics workstation | find "Statistics since 統計數據開始於"',$out,$status);
//$boottime = preg_replace ( "/\s(?=\s)/","\\1",$out[0]);
//$boottime_array = explode(' ',$boottime,2);
//echo $boottime_array[1];
相關文章
相關標籤/搜索