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