PHP gets the client network card mac physical address

WBOY
Release: 2016-07-25 09:13:28
Original
1857 people have browsed it

In php programming, by obtaining the user's mac address, you can bind it to the customer's computer, prevent spam registration, etc.
A very simple class. When using it, just print its macAddr attribute directly after instantiation.

Code:

  1. class Getmac{
  2. var $result = array(); // Returns a string array with MAC address
  3. var $macAddr;
  4. /*Construction*/
  5. function __construct($osType){
  6. switch ( strtolower($osType) ){
  7. case "unix": break;
  8. case "solaris": break;
  9. case "aix": break;
                                                                                                                                          $this->for_windows_os();

  10.                     $temp_array = array();                                             use using with use using ‐             ‐ ‐ ‐ ‐ ‐ ‐ foreach($this->result as $value){                                                    "."[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,

  11.                                                                                                                                                                                                                                                                                                                                                                     ​return $this->macAddr;

  12. }

  13. /*Getting method in linux system*/

  14. function for_linux_os(){

  15. @exec("ifconfig -a", $this->result);

  16. return $this->result;

  17. }

  18. /*Getting method in win system*/

  19. function for_windows_os(){

  20.   @exec("ipconfig /all", $this->result);
  21. H if ($ this-& gt; result) {
  22. Return $ This-& gt; Result;}} Else {
  23. $ ipconfig = $ _Server ["Windir"]. s_file ($ipconfig)) {
  24.                     @exec($ipconfig." /all", $this->result);
  25.                                                                                                                  e/ all", $this->result);                                              /*1. Implementation class 2. Directly access its macAddr attribute */
  26. $getMac = new Getmac(PHP_OS);
  27. echo $getMac->macAddr;
  28. ?>


  29. Copy code





  30. Client, network card



source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!