C # Read network status (in multiple cases)

Source: Internet
Author: User

System. Management.

 

Public String netstatus () <br/>{< br/> managementobjectcollection objects; <br/> string status = ""; <br/> managementobjectsearcher searcher = new managementobjectsearcher (); <br/> searcher. query. querystring = "select * From win32_networkadapter"; <br/> objects = searcher. get (); <br/> foreach (managementobject OBJ in objects) <br/>{< br/> foreach (propertydata P in OBJ. properties) <br/>{< br/> If (P. Name. Equals ("netconnectionstatus") <br/>{< br/> If (P. value! = NULL) <br/>{< br/> Status = P. value. tostring (); <br/>}< br/> switch (Status) <br/> {<br/> case "0": <br/> return "disconnected"; <br/> case "1 ": <br/> return "Connecting... "; <br/> case" 2 ": <br/> return" connected "; <br/> case" 3 ": <br/> return" disconnecting... "; <br/> case" 4 ": <br/> return" hardware not present "; <br/> case" 5 ": <br/> return "Hardware disabled"; <br/> case "6": <br/> return "Hardware Malfunction"; <br/> case "7 ": <br/> return "Media disconnected"; <br/> case "8": <br/> return "authenticating"; <br/> case "9 ": <br/> return "authentication succeeded"; <br/> case "10": <br/> return "authentication failed"; <br/> default: <br/> return ""; <br/>}</P> <p>}

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.