


PHP獲取MAC地址
添加時(shí)間:2014-7-4 7:26:51
添加:
思海網(wǎng)絡(luò)
獲取網(wǎng)卡的MAC地址原碼;目前支持WIN/LINUX系統(tǒng) 獲取機(jī)器網(wǎng)卡的物理(MAC)地址
- <?php
- /**
- 獲取網(wǎng)卡的MAC地址原碼;目前支持WIN/LINUX系統(tǒng)
- 獲取機(jī)器網(wǎng)卡的物理(MAC)地址
- **/
- class GetMacAddr{
- var $return_array = array(); // 返回帶有MAC地址的字串?dāng)?shù)組
- var $mac_addr;
- function GetMacAddr($os_type){
- switch ( strtolower($os_type) ){
- case "linux":
- $this->forLinux();
- break;
- case "solaris":
- break;
- case "unix":
- break;
- case "aix":
- break;
- default:
- $this->forWindows();
- break;
- }
- $temp_array = array();
- foreach ( $this->return_array as $value ){
- if (
- preg_match("/[0-9a-f][0-9a-f][:-]"."[0-9a-f][0-9a-f][:-]"."[0-9a-f][0-9a-f][:-]"."[0-9a-f][0-9a-f][:-]"."[0-9a-f][0-9a-f][:-]"."[0-9a-f][0-9a-f]/i",$value,
- $temp_array ) ){
- $this->mac_addr = $temp_array[0];
- break;
- }
- }
- unset($temp_array);
- return $this->mac_addr;
- }
- function forWindows(){
- @exec("ipconfig /all", $this->return_array);
- if ( $this->return_array )
- return $this->return_array;
- else{
- $ipconfig = $_SERVER["WINDIR"]."\system32\ipconfig.exe";
- if ( is_file($ipconfig) )
- @exec($ipconfig." /all", $this->return_array);
- else
- @exec($_SERVER["WINDIR"]."\system\ipconfig.exe /all", $this->return_array);
- return $this->return_array;
- }
- }
- function forLinux(){
- @exec("ifconfig -a", $this->return_array);
- return $this->return_array;
- }
- }
- //方法使用
- //$mac = new GetMacAddr(PHP_OS);
- //echo $mac->mac_addr;
- ?>
- 關(guān)鍵字:PHP、MAC、地址、網(wǎng)卡
新文章:
- CentOS7下圖形配置網(wǎng)絡(luò)的方法
- CentOS 7如何添加刪除用戶
- 如何解決centos7雙系統(tǒng)后丟失windows啟動(dòng)項(xiàng)
- CentOS單網(wǎng)卡如何批量添加不同IP段
- CentOS下iconv命令的介紹
- Centos7 SSH密鑰登陸及密碼密鑰雙重驗(yàn)證詳解
- CentOS 7.1添加刪除用戶的方法
- CentOS查找/掃描局域網(wǎng)打印機(jī)IP講解
- CentOS7使用hostapd實(shí)現(xiàn)無AP模式的詳解
- su命令不能切換root的解決方法
- 解決VMware下CentOS7網(wǎng)絡(luò)重啟出錯(cuò)
- 解決Centos7雙系統(tǒng)后丟失windows啟動(dòng)項(xiàng)
- CentOS下如何避免文件覆蓋
- CentOS7和CentOS6系統(tǒng)有什么不同呢
- Centos 6.6默認(rèn)iptable規(guī)則詳解