How to obtain the MAC address and IP address of the client NIC (1)

Source: Internet
Author: User

Obtain the client NicMacAddress andIPAddress methods(I)

Author:CodeMessy

In progressB/SFor structured systems, we often need to obtain some client information, suchIPAndMacIn combination with identity authentication. InASP. NETMedium,To obtain the serverMacIt is easy, but you need to obtainMacThe address does take a long time. The usual practice is to callWIN32APIOr directly callNBTSTATThere are a lot of problems with this, and another method is to directly use the client script. Here we useJavascriptThe advantage of doing so is that the server does not need to process it. Some clients can obtain it and transmit it to the server. The speed and reliability are better than those obtained from the server.
The specific implementation of HTML and JavaScript is as follows:

< Html > < Head > < Title > 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 Cmd.txt macaddr. Value = Unescape (macaddr );
Document. Forms [ 0 Cmd.txt ipaddr. Value = Unescape (ipaddr );
Document. Forms [ 0 Cmd.txt dnsname. 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 > </ Head >
< 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 Action = Nicpost. asp Method = Post > < Input Value = 00: 05: 5D: 0e: C7: Fa Name = Txtmacaddr >   < Input Value = 192.168.0.2 Name = Txtipaddr >   < Input Value = Typ Name = Txtdnsname >   </ Form > </ Body > </ Html >

In fact, the most important thing is to use two ActiveX:
<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 methods are provided by the system and do not need to be downloaded or registered.
The next job is to use scripts to interact with Activex. scripts can be JavaScript or vbs, but I personally like to use Js. In the next article, I will talk about how to obtain the MAC of the client on the server side with. net, and compare the advantages and disadvantages of these methods.
 

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.