PHP获取电脑网卡MAC地址

WBOY
Libérer: 2016-06-20 13:04:15
original
1443 Les gens l'ont consulté

获取网卡的MAC地址原码;目前支持WIN/LINUX系统 获取机器网卡的物理(MAC)地址

<?php  <br />    /**  <br />    获取网卡的MAC地址原码;目前支持WIN/LINUX系统  <br />    获取机器网卡的物理(MAC)地址  <br />    **/  <br />        <br />    class GetMacAddr{  <br />        <br />            var $return_array = array(); // 返回带有MAC地址的字串数组  <br />            var $mac_addr;  <br />        <br />            function GetMacAddr($os_type){  <br />                 switch ( strtolower($os_type) ){  <br />                          case "linux":  <br />                                    $this->forLinux();  <br />                                    break;  <br />                          case "solaris":  <br />                                    break;  <br />                          case "unix":  <br />                                     break;  <br />                           case "aix":  <br />                                     break;  <br />                           default:  <br />                                     $this->forWindows();  <br />                                     break;  <br />         <br />                  }  <br />         <br />                    <br />                  $temp_array = array();  <br />                  foreach ( $this->return_array as $value ){  <br />         <br />                            if (  <br />    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,  <br />    $temp_array ) ){  <br />                                     $this->mac_addr = $temp_array[0];  <br />                                     break;  <br />                           }  <br />         <br />                  }  <br />                  unset($temp_array);  <br />                  return $this->mac_addr;  <br />             }  <br />         <br />         <br />             function forWindows(){  <br />                  @exec("ipconfig /all", $this->return_array);  <br />                  if ( $this->return_array )  <br />                           return $this->return_array;  <br />                  else{  <br />                           $ipconfig = $_SERVER["WINDIR"]."\system32\ipconfig.exe";  <br />                           if ( is_file($ipconfig) )  <br />                              @exec($ipconfig." /all", $this->return_array);  <br />                           else  <br />                              @exec($_SERVER["WINDIR"]."\system\ipconfig.exe /all", $this->return_array);  <br />                           return $this->return_array;  <br />                  }  <br />             }  <br />         <br />         <br />         <br />             function forLinux(){  <br />                  @exec("ifconfig -a", $this->return_array);  <br />                  return $this->return_array;  <br />             }  <br />         <br />    }  <br />//方法使用<br />$mac = new GetMacAddr(PHP_OS);  <br />echo $mac->mac_addr;  <br />?>
Copier après la connexion


Étiquettes associées:
source:php.cn
Déclaration de ce site Web
Le contenu de cet article est volontairement contribué par les internautes et les droits d'auteur appartiennent à l'auteur original. Ce site n'assume aucune responsabilité légale correspondante. Si vous trouvez un contenu suspecté de plagiat ou de contrefaçon, veuillez contacter admin@php.cn
Tutoriels populaires
Plus>
Derniers téléchargements
Plus>
effets Web
Code source du site Web
Matériel du site Web
Modèle frontal
À propos de nous Clause de non-responsabilité Sitemap
Site Web PHP chinois:Formation PHP en ligne sur le bien-être public,Aidez les apprenants PHP à grandir rapidement!