PHP get a specific example of MAC address _php tutorial

Source: Internet
Author: User
This section shares the PHP code, the main features:
Gets the physical (MAC) address of the machine card.
Code:

Copy CodeThe code is as follows:
/**
* Get the physical (MAC) address of the machine card
* Currently supports Win/linux system
**/
Class Macaddinfo {
var $return _array = Array (); Returns an array of strings with MAC addresses
var $mac _addr;

function Macaddinfo ($os _type) {
Switch (Strtolower ($os _type)) {
Case "Linux":
$this->forlinux ();
Break
Case "Solaris":
Break
Case "UNIX":
Break
Case "AIX":
Break
Default:
$this->forwindows ();
Break
}
$temp _array = Array ();
foreach ($this->return_array as $value) {

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->mac_addr = $temp _array [0];
Break
}
}
unset ($temp _array);
return $this->mac_addr;
}

function Forwindows () {
@exec ("Ipconfig/all", $this->return_array);
if ($this->return_array)
return $this->return_array;
else {
$ipconfig = $_server ["windir"]. "/system32/ipconfig.exe";
if (Is_file ($ipconfig))
@exec ($ipconfig. "/all", $this->return_array);
Else
@exec ($_server ["windir"]. "/system/ipconfig.exe/all", $this->return_array);
return $this->return_array;
}
}

function Forlinux () {
@exec ("Ifconfig-a", $this->return_array);
return $this->return_array;
}
}
Invoke Example
$mac = new Macaddinfo (php_os);
Echo $mac->mac_addr;
?>

http://www.bkjia.com/PHPjc/621689.html www.bkjia.com true http://www.bkjia.com/PHPjc/621689.html techarticle This section shares the PHP code, the main function: Get the physical (MAC) address of the machine card. Code: Copy code code as follows: PHP/** * Get the physical (MAC) address of the Machine network card * currently ...

  • 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.