PHP/JS get the implementation code of the client MAC address

Source: Internet
Author: User
Tags php and
This article mainly introduces how to obtain the Customer degree MAC address in PHP and JS respectively, need friend can refer to the next

Nonsense not to speak more, directly on the code!

Copy Code code as follows:


<?php


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 "<br/>";





//Get client


//Linux


$command = "Arp-a {$_server[' remote_addr ']}";


Echo $command;


echo "<br/>";


$result = ' {$command} ';





//Windows


$command = "nbtstat-a {$_server[' remote_addr ']}";


Echo $command;


echo "<br/>";


$result = ' {$command} ';


Print_r ($result);


?>

There is no big problem getting the server-side logic, and there may be permissions issues.
It may be slower to get the client, and the Arp/nbstat command execution will be slower.

Copy Code code as follows:


<script language= "JScript" event= "oncompleted (Hresult,perrorobject, Pasynccontext)" for= "foo" >


Document.forms[0].lbmacaddr.value=unescape (MACADDR);


</script>


<script language= "JScript" event= "OnObjectReady (objobject,objasynccontext)" for= "foo" >


if (objobject.ipenabled!= null && objobject.ipenabled!= "undefined" && objobject.ipenabled = True    && objobject.macaddress!= null && objobject.macaddress!= "undefined") macaddr = objobject.macaddress;


</script>


<object id= "locator" classid= "Clsid:76a64158-cb41-11d1-8b02-00600806d9b6" ></object>


<object id= "foo" classid= "clsid:75718c9a-f029-11d1-a1ac-00c04fb6c223" ></object>


<script language= "JScript" >


var service = Locator.    ConnectServer ();


var macaddr;


var ipaddr;


var domainaddr;


var sdnsname;


service. Security_.    impersonationlevel=3;


service.    Instancesofasync (foo, ' Win32_NetworkAdapterConfiguration ');


</script>


<form><input type= "text" id= ' lbmacaddr ' name= lbmacaddr '/></form> '

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

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.