It is easy to use to detect networks on Windows 8
Networkinformation class
The class contains the following methods and events:
Public static event networkstatuschangedeventhandler networkstatuschanged; // public static ireadonlylist <connectionprofile> getconnectionprofiles (); public static ireadonlylist
VaR ICP = networkinformation. getinternetconnectionprofile (); If (ICP! = NULL & ICP. networkadapter! = NULL) {var hostname = networkinformation. gethostnames (). singleordefault (HN => hn. ipinformation! = NULL & hn. ipinformation. networkadapter. networkadapterid = ICP. networkadapter. networkadapterid); system. diagnostics. debug. writeline ("available network IP:" + hostname. displayname); system. diagnostics. debug. writeline ("network status:" + ICP. getnetworkconnectivitylevel ());}
Use
Networkinformation. getinternetconnectionprofile (); obtain the networkadapter network device after obtaining the network configuration.
Getnetworkconnectivitylevel () to get the status of the current network, which is an enumeration type, as follows:
// Summary: // No connectivity. none = 0, // Summary: // local network access only. localaccess = 1, // Summary: // limited Internet access. this value indicates captive portal connectivity, // where local access to a web portal is provided, but access to the internet // requires that specific credentials are provided by the portal. this level // of connectivity is generally encountered when using connections hosted in // public locations (e.g. coffee shops and book stores ). // limited access constrainedinternetaccess = 2, /// Summary: // local and Internet access. internet access internetaccess = 3,
You can use networkstatuschanged in networkinformation to listen for network changes and perform corresponding processing.
You are welcome to reprint it. Please indicate that it is fromBeyondblog blog