Get the client Nic MAC address and IP address to implement JS code _javascript skills

Source: Internet
Author: User
In the B/s structure of the system, we often need to obtain some information on the client, such as IP and Mac, in conjunction with authentication. Getting a server-side Mac is easy, but getting the client's MAC address takes a lot of effort, usually by calling Win32API or calling the nbtstat command directly, which has many problems, and the other way is to use client script directly, We use JavaScript here, the advantage of this is that there is no need for server-side processing, there is a client to obtain, passed to the server side, and speed and reliability than on the server to get better.
the concrete implementations of HTML and JavaScript are as follows
Copy Code code as follows:

<HTML>
<HEAD>
&LT;TITLE&GT;WMI Scripting Html</title>
<meta http-equiv=content-type content= "text/html; charset=gb2312 ">
<script language=jscript event= "oncompleted (Hresult,perrorobject, Pasynccontext)" for=foo>
Document.forms[0].txtmacaddr.value=unescape (MACADDR);
Document.forms[0].txtipaddr.value=unescape (IPADDR);
Document.forms[0].txtdnsname.value=unescape (Sdnsname);
Document.formbar.submit ();
</SCRIPT>
<script language=jscript Event=onobjectready (objobject,objasynccontext) for=foo>
if (objobject.ipenabled!= null && objobject.ipenabled!= "undefined" && objobject.ipenabled = = True)
{
if (objobject.macaddress!= null && objobject.macaddress!= "undefined")
MACADDR = objobject.macaddress;
if (objobject.ipenabled && objobject.ipaddress (0)!= null && objobject.ipaddress (0)!= "undefined")
ipaddr = objobject.ipaddress (0);
if (objobject.dnshostname!= null && objobject.dnshostname!= "undefined")
Sdnsname = Objobject.dnshostname;
}
</SCRIPT>
<meta content= "MSHTML 6.00.2800.1106" name=generator><BODY>
<object Id=locator Classid=clsid:76a64158-cb41-11d1-8b02-00600806d9b6 viewastext></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 Id=formfoo Name=formbar method=post>
<input type= "Text" name=txtmacaddr>
<input type= "Text" name=txtipaddr>
<input type= "Text" name=txtdnsname>
</FORM>
</BODY>
</HTML>

In fact, the most important thing is to use two ActiveX
Copy Code code as follows:

<object Id=locator Classid=clsid:76a64158-cb41-11d1-8b02-00600806d9b6 viewastext></object>
<object Id=foo classid=clsid:75718c9a-f029-11d1-a1ac-00c04fb6c223></object>

However, these two ActiveX systems are self-contained and do not need to be downloaded or registered.
The next step is to use scripting and ActiveX interactions, which can be either JS or VBS.

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.