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