Get the physical (MAC) address of the machine card

Source: Internet
Author: User
<无详细内容>
  1. /**
  2. Get the physical (MAC) address of the machine card
  3. **/
  4. Class Getmacaddr
  5. {
  6. var $return _array = Array (); Returns an array of strings with MAC addresses
  7. var $mac _addr;
  8. function getmacaddr ($os _type)
  9. {
  10. Switch (Strtolower ($os _type))
  11. {
  12. Case "Linux":
  13. $this-Forlinux ();
  14. Break
  15. Case "Solaris":
  16. Break
  17. Case "UNIX":
  18. Break
  19. Case "AIX":
  20. Break
  21. Default
  22. $this-forwindows ();
  23. Break
  24. }
  25. $temp _array = Array ();
  26. foreach ($this-Return_array as $value)
  27. {
  28. 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))
  29. {
  30. $this-mac_addr = $temp _array[0];
  31. Break
  32. }
  33. }
  34. unset ($temp _array);
  35. return $this, mac_addr;
  36. }
  37. function Forwindows ()
  38. {
  39. @exec ("Ipconfig/all", $this-Return_array);
  40. if ($this-Return_array)
  41. return $this, Return_array;
  42. else{
  43. $ipconfig = $_server["windir"]. " \system32\ipconfig.exe ";
  44. if (Is_file ($ipconfig))
  45. @exec ($ipconfig. "/all", $this-Return_array);
  46. Else
  47. @exec ($_server["windir"]. " \system\ipconfig.exe/all ", $this-Return_array);
  48. return $this, Return_array;
  49. }
  50. }
  51. function Forlinux ()
  52. {
  53. @exec ("Ifconfig-a", $this-Return_array);
  54. return $this, Return_array;
  55. }
  56. }
  57. ?>
  58. $mac = new Getmacaddr (php_os);
  59. Echo $mac-mac_addr;
  60. ?>
Copy Code
  • 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.