PHP/JS get the implementation code for the client MAC address _php tutorial

Source: Internet
Author: User
Don't say much nonsense, just go to the code!

Copy CodeThe code is as follows:
Class Macaddr
{
Public $returnArray = Array ();
Public $macAddr;

function __contruct ($os _type=null) {
if (Is_null ($os _type)) $os _type = Php_os;
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->returnarray 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->macaddr = $temp _array[0];
Break
}
}
unset ($temp _array);
return $this->macaddr;
}

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

function Forlinux () {
@exec ("Ifconfig-a", $this->returnarray);
return $this->returnarray;
}
}

$mac = new Macaddr (php_os);
Echo $mac->macaddr;
echo "
";

Get Client
Linux
$command = "Arp-a {$_server[' remote_addr ']}";
Echo $command;
echo "
";
$result = ' {$command} ';

Windows
$command = "Nbtstat-a {$_server[' remote_addr ']}";
Echo $command;
echo "
";
$result = ' {$command} ';
Print_r ($result);
?>

There is no big problem getting the logic on the server side, there may be permissions issues.
When the client is fetched, it may be slow and the Arp/nbstat command execution will be slow.

Copy the Code code as follows:






Only applicable to IE browser, and there will be alarm prompts, very regrettable.

http://www.bkjia.com/PHPjc/328054.html www.bkjia.com true http://www.bkjia.com/PHPjc/328054.html techarticle don't say much nonsense, just go to the code! Copy the code as follows:? PHP class Macaddr {public $returnArray = array (), public $macAddr, function __contruct ($os _type=null) {if (is_ Nu ...

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