博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
php 读取windows 的系统版本,硬盘,内存,网卡,数据流量等
阅读量:6679 次
发布时间:2019-06-25

本文共 3642 字,大约阅读时间需要 12 分钟。

php 读取windows 的系统版本,硬盘,内存,网卡,数据流量等

 

\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 ,返回其它的是 workstationif($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];

 

转载于:https://www.cnblogs.com/yisuo/p/9462663.html

你可能感兴趣的文章
Confluence WIKI 安装、破解及添加汉化包(Windows)
查看>>
一起入门Citrix_XenDesktop7系列 二-- 跟着图片通过XenDesktop7交付(发布)应用与共享桌面...
查看>>
MyBatis学习手记(一)MaBatis入门
查看>>
SCTF-2014 writeup(部分)
查看>>
Elasticsearch 连接查询
查看>>
Retrofit入门
查看>>
设置Exchange 通讯组接收外部组织邮件
查看>>
观点:正在消逝的运维江湖
查看>>
istio 监控,遥测 (理论)
查看>>
Oracle insert 多条记录
查看>>
Python学习-baseNo.2
查看>>
spring data mongo 复合索引
查看>>
修改Windows Server 2008远程桌面连接端口
查看>>
Android获取指定目录下的文件代码
查看>>
java.lang.ClassNotFoundException: com.mysql.jdbc.Driver
查看>>
程序猿,你的坐姿正确吗?
查看>>
新疆之春(二)魂牵梦绕赛里木湖
查看>>
解析el表达式出错
查看>>
vmware实现nat上网
查看>>
Linux一键安装Aria2+Yaaw+FileManager实现BT磁力下载,并在线查看/观看
查看>>