MAC address and IP address

Source: Internet
Author: User
Tags servervariables

The project requires the MAC address and IP address of the client, but many examples are found on the Internet. However, after testing, the server code is obtained. Later, I saw an article saying, the client's MAC address cannot be obtained because of the server code running on this webpage.

Below are some of the information we found, but they all get the client code. Below are some highlights of the code found on the Internet:

Label1.text = "// Client IP:" + request. servervariables. get ("remote_addr "). tostring () + "<br>" + "// client host name:" + request. servervariables. get ("remote_host "). tostring () + "<br>" + "// client browser ie:" + request. browser. browser + "<br>" + "// client browser version:" + request. browser. majorversion + "<br>" + "// client operating system:" + request. browser. platform + "<br>" + "// server IP:" + request. servervariables. get ("local_addr "). tostring () + "<br>" + "// server name:" + request. servervariables. get ("SERVER_NAME "). tostring () + "<br>"; string stringmac = ""; string stringip = ""; managementclass MC = new managementclass ("win32_networkadapterconfiguration"); managementobjectcollection MOC = MC. getinstances (); foreach (managementobject Mo in MoC) {If (bool) Mo ["ipenabled"] = true) {stringmac + = Mo ["macaddress"]. tostring (); // obtain the NIC address string [] ipaddresses = (string []) Mo ["IPaddress"]; // obtain the local IP address if (ipaddresses. length> 0) stringip = ipaddresses [0]; label1.text + = "<br> Mac:" + stringmac + "/IP:" + stringip; if (stringip = "192.168.1.45") label1.text + = "<br> I get you: 192.168.1.45 <br> ";}}

Therefore, the server cannot obtain its IP address. The following describes how to use JavaScript to access its MAC address. Unfortunately, this requires interaction with active objects! The following code is implemented using JavaScript.

Javascript get Mac

<! Doctype HTML public "-// W3C // dtd xhtml 1.0 transitional // en" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <HTML xmlns = "http://www.w3.org/1999/xhtml"> 

Note: You can use request. userhostaddress to obtain the IP address. However, if your client system is window2008 R2, the obtained IP address will be IPv6.

Refer to the following URL:

Http://topic.csdn.net/u/20100807/09/58faa224-4f26-4177-9ddc-5df8a0292f14.html

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.