1 Client IP:2Request.ServerVariables.Get ("REMOTE_ADDR"). ToString ();3 Client host Name:4Request.ServerVariables.Get ("Remote_host"). ToString ();5 client browser ie:6 Request.Browser.Browser;7 client Browser version number:8 Request.Browser.MajorVersion;9 client operating system:Ten Request.Browser.Platform; One Server IP: ARequest.ServerVariables.Get ("local_addr"). ToString (); - Server name: -Request.ServerVariables.Get ("server_name"). ToString (); the If you want to learn more about ServerVariables, you can use - foreach(String oinchrequest.servervariables) { -Response.Write (o+"="+request.servervariables[o]+"<br>"); - } + stringStringmac =""; - stringSTRINGIP =""; +ManagementClass MC =NewManagementClass ("Win32_NetworkAdapterConfiguration"); AManagementobjectcollection moc=MC. GetInstances (); at - foreach(ManagementObject MOinchMOC) - { - if((BOOL) mo["ipenabled"] ==true) - { -Stringmac + = mo["MACAddress"]. ToString ();//get the address of the NIC in string[] ipaddresses = (string[]) mo["IPAddress"];//get the local IP address - if(Ipaddresses.length >0) toSTRINGIP = ipaddresses[0]; +Response.Write (stringmac+"/"+STRINGIP); - } the } *asp.net+How does C # get the MAC address of the client NIC? $ //To refer to the following two namespacesPanax Notoginseng usingSystem.Diagnostics; - usingSystem.Text.RegularExpressions; the + //get the network card Physical Address (MAC) of the remote client A Public stringGetmac (stringIP)//para IP is the client ' s IP the { + stringdirresults=""; -ProcessStartInfo psi =NewProcessStartInfo (); $Process proc =NewProcess (); $Psi. FileName ="nbtstat"; -Psi. Redirectstandardinput =false; -Psi. Redirectstandardoutput =true; thePsi. Arguments ="-A"+IP; -Psi. UseShellExecute =false;WuyiProc =Process.Start (PSI); theDirresults =Proc. Standardoutput.readtoend (); - Proc. WaitForExit (); WuDirresults=dirresults.replace ("\ r",""). Replace ("\ n",""). Replace ("\ t",""); - AboutRegex reg=NewRegex ("mac[]{0,}address[]{0,}=[]{0,} (?<key> (.) *?)) __mac", regexoptions.ignorecase|regexoptions.compiled); $Match Mc=reg. Match (dirresults+"__mac"); - - if(MC. Success) - { A returnMc. groups["Key"]. Value; + } the Else - { $reg=NewRegex ("Host not found", regexoptions.ignorecase|regexoptions.compiled); theMc=Reg. Match (dirresults); the if(MC. Success) the { the return "Host not found!"; - } in Else the { the return ""; About } the } the } the + //Print the client's NIC Physical Address (MAC) on the page -Response.Write ( This. Getmac (Request.UserHostAddress.ToString ())); the Bayi Get CPU serial number, HDD ID, Nic MAC address the Private voidGetInfo () the { - stringCpuInfo ="";//CPU Serial Number -ManagementClass Cimobject =NewManagementClass ("Win32_Processor"); theManagementobjectcollection MOC =Cimobject. GetInstances (); the foreach(ManagementObject moinchMOC) the { theCpuInfo = mo. properties["Processorid"]. Value.tostring (); -Response.Write ("CPU Serial Number:"+cpuinfo.tostring ()); the } the the //get the hard drive ID94 String HDid; theManagementClass Cimobject1 =NewManagementClass ("win32_diskdrive"); theManagementobjectcollection Moc1 =Cimobject1. GetInstances (); the foreach(ManagementObject moinchMoc1)98 { AboutHDid = (string) mo. properties["Model"]. Value; -Response.Write ("Hard Drive serial number:"+hdid.tostring ());101 }102 103 104 //get the NIC hardware address the 106ManagementClass MC =NewManagementClass ("Win32_NetworkAdapterConfiguration");107Managementobjectcollection MOC2 =MC. GetInstances ();108 foreach(ManagementObject moinchmoc2)109 { the if((BOOL) mo["ipenabled"] ==true)111Response.Write ("MAC address\t{0}"+mo["MacAddress"]. ToString ()); the mo. Dispose ();113 } the}
Get the server IP, client IP, and network card Physical address in C #