php获取客户端网卡mac物理地址

WBOY
Freigeben: 2016-07-25 09:13:28
Original
1803 Leute haben es durchsucht

php编程中,获取到用户mac地址,就可以实现与客户电脑的绑定、防止垃圾注册等。
一个非常简单的类,使用时只要实例化后直接打印它的macAddr属性即可。

代码:

  1. class Getmac{
  2.     var $result = array(); // 返回带有MAC地址的字串数组
  3.     var $macAddr;
  4.     /*构造*/
  5.     function __construct($osType){
  6.         switch ( strtolower($osType) ){
  7.             case "unix": break;
  8.             case "solaris": break;
  9.             case "aix": break;
  10.             case "linux": {
  11.                 $this->for_linux_os();
  12.             }break;
  13.             default: {
  14.                 $this->for_windows_os();
  15.             }break;
  16.         }
  17.         $temp_array = array();
  18.         foreach($this->result as $value){
  19.             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,
  20.                 $temp_array ) ){
  21.                 $this->macAddr = $temp_array[0];
  22.                 break;
  23.             }
  24.         }
  25.         unset($temp_array);
  26.         return $this->macAddr;
  27.     }
  28.     /*linux系统中获取方法*/
  29.     function for_linux_os(){
  30.         @exec("ifconfig -a", $this->result);
  31.         return $this->result;
  32.     }
  33.     /*win系统中的获取方法*/
  34.     function for_windows_os(){
  35.         @exec("ipconfig /all", $this->result);
  36.         if ( $this->result ) {
  37.             return $this->result;
  38.         } else {
  39.             $ipconfig = $_SERVER["WINDIR"]."\system32\ipconfig.exe";
  40.             if(is_file($ipconfig)) {
  41.                 @exec($ipconfig." /all", $this->result);
  42.             } else {
  43.                 @exec($_SERVER["WINDIR"]."\system\ipconfig.exe /all", $this->result);
  44.                 return $this->result;
  45.             }
  46.         }
  47.     }
  48. }
  49. /*1.实现化类   2.直接访问它的macAddr属性*/
  50. $getMac = new Getmac(PHP_OS);
  51. echo $getMac->macAddr;
  52. ?>
复制代码


客户端, 网卡


Quelle:php.cn
Erklärung dieser Website
Der Inhalt dieses Artikels wird freiwillig von Internetnutzern beigesteuert und das Urheberrecht liegt beim ursprünglichen Autor. Diese Website übernimmt keine entsprechende rechtliche Verantwortung. Wenn Sie Inhalte finden, bei denen der Verdacht eines Plagiats oder einer Rechtsverletzung besteht, wenden Sie sich bitte an admin@php.cn
Beliebte Tutorials
Mehr>
Neueste Downloads
Mehr>
Web-Effekte
Quellcode der Website
Website-Materialien
Frontend-Vorlage
Über uns Haftungsausschluss Sitemap
Chinesische PHP-Website:Online-PHP-Schulung für das Gemeinwohl,Helfen Sie PHP-Lernenden, sich schnell weiterzuentwickeln!