C # get computer information

Source: Internet
Author: User
Tags servervariables

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

Related Article

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.