[C #] Determine if the computer is in a connected network (networked) state

Source: Internet
Author: User

C # Implementation to determine if a computer is in a connected network (networked) state

if (systeminformation.network) {MessageBox.Show ("The computer is already networked");      } else {MessageBox.Show ("The computer is not yet networked"); }

C # Implementation Gets the IP address of the computer

Method 1

 <summary>   ///  Get IP Address    /// </summary>  IP address of   /// <returns>string type </returns>   public string  Getipaddress ()    {           string  text = string. empty;           string result;            try           {                    ipaddress[] addresslist = dns.gethostentry (Dns.gethostname ()). addresslist;                    IPAddress[] array = addressList;                    for  (Int i = 0; i < array . length; i++)                     {                            ipaddress ipaddress =  array[i];                            if  (!ipaddress.isipv6sitelocal)                             {                                 &nBsp;   text = ipaddress.tostring ();                             }                    }                   if  (String. IsNullOrEmpty (text))                    {                            throw new exception ("Can  not get this computer ip address. ");                  }                   result = text;           }          catch   (EXCEPTION&NBSP;EX)           {                   throw new  Exception ("getipaddress exception: "  + ex. Message);          }            return result;   }

Method 2

Public void getipaddress (REF&NBSP;STRING&NBSP;HOST,REF&NBSP;STRING&NBSP;IP)    {            try           {                    host = dns.gethostname (). ToUpper ();                    ipaddress[] addresslist = dns.gethostentry (Dns.GetHostName ()). addresslist;                    IPAddress[] array = addressList;                    for  (int i = 0;  i < array. length; i++)                    {                             IPAddress iPAddress = array[i];                             if  (!ipaddress.isipv6sitelocal)                             {                                          ip = ipaddress.tostring ();                            }                    }                    if  (String. IsNullOrEmpty (host))                     {                            throw new exception (" Can not get this computer name. ");                     }                    if  (String. IsNullOrEmpty (IP))                    {                             throw new exception ("Can not get this computer ip  address. ");                     }           }            catch (Exception ex)             {                    throw new exception ("Getipaddress exception:"  + ex. Message);            }   }


This article from "Flower Blossom Fall" blog, declined reprint!

[C #] Determine if the computer is in a connected network (networked) state

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.