Get MAC address in JS

Source: Internet
Author: User
Function  Macinfo (){  VaR Locator = New Activexobject ("wbemscripting. swbemlocator" );  VaR Service = locator. connectserver ("." );  VaR Properties = service. execquery ("select * From win32_networkadapterconfiguration where ipenabled = true" );  VaR E = New Enumerator (properties );{  VaR P = E. Item ();  VaR MAC = P. macaddress; document. getelementbyid ( "<% = Hd_macaddress.clientid %>"). value = Unescape (MAC );}} 

There are other methods:

<Script language = JScript event = "oncompleted (hresult, perrorobject, pasynccontext )" For = Foo> Document. getelementbyid ( "Txtmacaddr"). value =Unescape (macaddr); document. getelementbyid ( "Txtipaddr"). value = Unescape (ipaddr); document. getelementbyid ( "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> <Object ID = "fool" 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 = Fool. connectserver ();  VaR  Macaddr;  VaR  Ipaddr;  VaR Domainaddr;  VaR  Sdnsname; service. Security _. impersonationlevel = 3 ; Service. instancesofasync (Foo, 'Win32 _ networkadapterconfiguration' ); </SCRIPT>

 

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.