PHP gets a specific instance of the MAC address

Source: Internet
Author: User

  share a case of PHP to get the MAC address of the code, learn how to read the hardware information in PHP, the code for Windows, Linux systems. Have a friend in need of reference study under

This section shares the PHP code, the main function: Get the Machine network card Physical (MAC) address. Code:     Code as follows: <?php  /**    * Acquire the physical (MAC) address of the Machine network card * currently supports Win/linux system    **/  class Macaddinfo {          var $return _array = Array ();//return string array with MAC address       &NBS P var $mac _addr;         function macaddinfo ($os _type) {          switch (strtolower $os _ty PE) {              case "Linux":               & nbsp   $this->forlinux ();                   break;               case "Solaris":                   break;               case "UNIX":                 &NB Sp Break               Case "AIX":                  break;               default:                   $this->forwindows ();                   break;                  }          $temp _array = Array ();           foreach ($this->return_array as $value) {          &NBS P     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->ma C_ADDR = $temp _array [0];                   break;               {                &NBSp unset ($temp _array);           return $this->mac_addr;      }         function forwindows () {          @exec ("IPC Onfig/all ", $this->return_array);           if ($this->return_array)               return $th is->return_array;           else {              $ipconfig = $_server ["windir"] . "/system32/ipconfig.exe";               if (Is_file ($ipconfig))             &NBS P     @exec ($ipconfig. "/all", $this->return_array);               else                   @exec ($_server ["windir"]. "/system/ipconfig.exe/all", $this->return_array);               return $this->return_array;           {     }         function Forlinux () {  &NBSP ;       @exec ("Ifconfig-a", $this->return_array);           return $this->return_array;      }  }  //Call example//$mac = new Macaddinfo (php_os);    //echo $mac->mac_addr;    ?>     

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.