JS Get client MAC Address

Source: Internet
Author: User

Recently encountered a demand, the hospital requires the call center account must correspond to the MAC address, that is, the MAC address must correspond with the call center account can be used, this can be me, this requirement requires each time to determine the user login computer MAC address whether there is a call center account, of course, only for IE browser, After all, the other browser is directly to prohibit this feature.

So first question one: How to get a local MAC address through page access

Question two: Each computer has more than one MAC address, then you should choose which MAC address

MAC address is the physical address of each computer link network, is the unique identity, want to get the computer from the browser information, then need to ActiveX, so other browsers are no way to get MAC address through JS.

Method One: (recommended) requires client settings to join the server address to the trusted site

<html>

<head>

<title> get client MAC address </title>

</head>

<body>

<object classid="Clsid:76a64158-cb41-11d1-8b02-00600806d9b6" id="locator" style= "Display:none;visibility:hidden"></object>

<object classid="clsid:75718c9a-f029-11d1-a1ac-00c04fb6c223" id= "foo" style=" Display:none;visibility:hidden "></object>

<form name="MyForm">

<BR/>mac Address:<input type="text" name="macAddress">

<BR/>IP Address:<input type="text" name="ipAddress">

<br/> hostname:<input type="text" name="HostName">

</form>

</body>

</html>

<script language="javascript">

var smacaddr="";

var sipaddr="";

var sdnsname="";

var service = Locator.  ConnectServer ();

Service. Security_.  Impersonationlevel=3;

Service. Instancesofasync (foo, ' Win32_NetworkAdapterConfiguration ');

</Script>

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

if (objobject.ipenabled! = NULL && objobject.ipenabled! = "undefined" && objobject.ipenabled = = True ){  

if (objobject.ipenabled && objobject.ipaddress (0)!=null && objobject.ipaddress (0)! = "undefined")

sipaddr = objobject.ipaddress (0);

if (objobject.macaddress! = null &&objobject.macaddress! = "undefined")

smacaddr = objobject.macaddress;

if (objobject.dnshostname! = null &&objobject.dnshostname! = "undefined")

sdnsname = objobject.dnshostname;

}

</Script>

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

Myform.macaddress.value=smacaddr;

Myform.ipaddress.value=sipaddr;

Myform.hostname.value=Sdnsname;

</Script>

Method Two:

<! DOCTYPE html>

<title> Get computer hardware information </title>

<meta name= "keywords" content= "keyword1,keyword2,keyword3" >

<meta name= "description" content= "This is my page" >

<meta name= "Content-type" content= "text/html; CHARSET=GBK ">

<body>

<script id= "Clienteventhandlersjs" language= "JavaScript" charset= "Utf-8" >

Http://www.w3school.com.cn/htmldom/dom_obj_navigator.asp

/****************************************** above for browser information, the following is the PC information ************************************************/ try {var locator = new ActiveXObject ("WbemScripting.SWbemLocator");

var service = Locator. ConnectServer (".");

Get Network connection Information

function Ipinfo () {

var properties = Service. ExecQuery ("select * from Win32_NetworkAdapterConfiguration Where ipenabled=true");

var e = new Enumerator (properties);

var info= "<table border=1>";

info+= "<tr bgcolor= ' #CDEDED ' style= ' font-weight:bold; ' >

<TD width= ' > Network connection Information:</td></tr> ";

var I=1;

for (;! E.atend (); E.movenext ()) {

var p = e.item ();

info+= "<tr style= ' color:red ' ><td >mac Address" +i+ ":" + p.macaddress + "</td></tr>";     info+= "<tr style= ' color:red ' ><td >ip Address" +i+ ":" + p.ipaddress (0) + "</td></tr>";    i++; }

info+= "</table>";   return info; }

function Pcinfo () {//All information

var info=ipinfo ();

/* Info+=disk (); Info+=raminfo ();

Info+=mainboard ();

Info+=ipinfo ();

Info+=keyboardinfo ();

Info+=rominfo ();

Info+=softdisk (); */document.getElementById (' Elinfo '). Innerhtml=info;

return info; }} catch (e) {document.write (e);}

/****************************************** above for PC information ************************************************/

</script>

<body > <!--<input id= "Button1" type= "button" value= "Browser All Information" name= "Button1" Language=javascript onclick= " Allinfo () ">-

<input id= "Button1" type= "button" value= "Client PC Info" name= "Button1" Language=javascript onclick= "Pcinfo ()" >

<div id= "Elinfo" >

</div> </body>

JS Get client MAC Address

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.