Tested the following method to get Mac cross-platform
protected Override voidOnLoad (EventArgs e) {Response.Write (string. Join ("<br/>", Getmacstring ())); Response.Write ("<br/>");Base. OnLoad (e); } PublicNetworkinterface[] Netcardinfo () {returnNetworkinterface.getallnetworkinterfaces (); } Public string[] getmacstring () {stringStrmac = ""; Networkinterface[] interfaces = Networkinterface.getallnetworkinterfaces ();foreach(NetworkInterface niinchInterfaces) {if(NI. Operationalstatus = = operationalstatus.up) {Strmac + = ni. Getphysicaladdress (). ToString () + "|"; } }returnStrmac.split (' | '); }
Related articles:
C #/S program get MAC address three ways http://www.cnblogs.com/yzb305070/archive/2011/04/03/2004364.html
Report:
// <summary>/// Get the server IP for the current request, and the corresponding MAC address// </summary>// <returns>[the server Ip,mac address currently requested]</returns> Public string[] Getrequestipmac () {string[] result =New string[2];stringServerName = page.request.servervariables["server_name"];stringRequestserverip = page.request.servervariables["local_addr"];if(ServerName = = "localhost") {result[0] ="localhost"; }Else{Result[0] = Requestserverip.tolower (); ManagementClass MC =NewManagementClass ("Win32_NetworkAdapterConfiguration"); Managementobjectcollection MOC = MC. GetInstances ();foreach(ManagementObject moinchMOC) {Try{if((BOOL) mo["ipenabled"] ==true) {string[] ipaddresses = (string[]) mo["IPAddress"];if(Ipaddresses.length > 0) { for(inti = 0; i < ipaddresses.length; i++) {if(Ipaddresses[i] = = Requestserverip) {Result[1] = mo["MacAddress"]. ToString (). ToLower (); Break; } } }if(! String.IsNullOrEmpty (Result[1])) { Break; } } }finally{mo. Dispose (); } } }returnResult;}
How to get Mac from Linux win general