Get computer information, get remote computer information when you need to shut down the remote machine's firewall, or not get the relevant information.
usingSystem;usingSystem.Collections.Generic;usingSystem.Linq;usingsystem.web;usingSystem.Text;usingSystem.Runtime.InteropServices;/// <summary>///Summary description of Nethelper/// </summary> Public classnethelper{ PublicNethelper () {} Public Static stringGetbrowsertype () {returnHttpContext.Current.Request.Browser.Type; } Public Static stringgetsysversion () {stringAgent = httpcontext.current.request.servervariables["http_user_agent"]; if(Agent.indexof ("NT 4.0") >0) { return "Windows NT"; } Else if(Agent.indexof ("NT 5.0") >0) { return "Windows $"; } Else if(Agent.indexof ("NT 5.1") >0) { return "Windows XP"; } Else if(Agent.indexof ("NT 5.2") >0) { return "Windows 2003"; } Else if(Agent.indexof ("NT 6.0") >0) { return "Windows Vista"; } Else if(Agent.indexof ("WindowsCE") >0) { return "Windows CE"; } Else if(Agent.indexof ("NT") >0) { return "Windows NT"; } Else if(Agent.indexof ("9x") >0) { return "Windows ME"; } Else if(Agent.indexof ("98") >0) { return "Windows 98"; } Else if(Agent.indexof (" the") >0) { return "Windows"; } Else if(Agent.indexof ("Win32") >0) { return "Win32"; } Else if(Agent.indexof ("Linux") >0) { return "Linux"; } Else if(Agent.indexof ("SunOS") >0) { return "SunOS"; } Else if(Agent.indexof ("Mac") >0) { return "Mac"; } Else if(Agent.indexof ("Linux") >0) { return "Linux"; } Else if(Agent.indexof ("Windows") >0) { return "Windows"; } return "Unknow"; } /// <summary> ///If there is an agent then pass the proxy directly to the value/// </summary> /// <returns></returns> Public Static stringGetclientip () {if(httpcontext.current.request.servervariables["Http_via"] !=NULL) returnhttpcontext.current.request.servervariables["http_x_forwarded_for"]. ToString (); Else returnhttpcontext.current.request.servervariables["REMOTE_ADDR"]. ToString (); } Public Static stringgethostname () {returngethostname (Getclientip ()); } Public Static stringGetmac () {returnGetmac (Getclientip ()); } Public Static stringGetHostName (stringipstr) { stringHostName =string. Empty; Try{System.Net.IPAddress IP=System.Net.IPAddress.Parse (IPSTR); System.Net.IPHostEntry Host=System.Net.Dns.GetHostEntry (IP); HostName=host. HostName; } Catch { } returnHostName; } [DllImport ("Iphlpapi.dll")] Static extern intSendarp (Int32 destip, Int32 Srcip,refInt64 Macaddr,refInt32 Phyaddrlen); [DllImport ("Ws2_32.dll")] Static externInt32 inet_addr (stringipaddr); /// <summary> ///Sendarp get MAC address/// </summary> /// <param name= "Remoteip" >IP address of the target machine (192.168.1.1)</param> /// <returns>MAC address of the target machine</returns> Public Static stringGetmac (stringRemoteip) {StringBuilder macAddress=NewStringBuilder (); Try{Int32 remote=inet_addr (REMOTEIP); Int64 Macinfo=NewInt64 (); Int32 length=6; Sendarp (remote,0,refMacinfo,reflength); stringtemp = convert.tostring (Macinfo, -). PadLeft ( A,'0'). ToUpper (); intx = A; for(inti =0; I <6; i++) { if(i = =5) {macaddress.append (temp. Substring (x-2,2)); } Else{macaddress.append (temp. Substring (x-2,2) +"-"); } x-=2; } returnmacaddress.tostring (); } Catch { returnmacaddress.tostring (); } }}
C # get computer information