How to retrive network outage data in c# and c++?

Joshi, Aparna 1 Reputation point
2021-12-06T13:28:36.02+00:00

is there any API available in C++ and C# which can generate events on below network change.

1.Identify if network disconnected because of hibernate, sleep, restart, Aeroplane mode actions
2.Any event gets generated if wifi is connected but the internet is not accessible? (Wifi icon turns yellowish)
3.Any event gets generated if LAN is connected but the internet is not accessible?
4.If connected to both LAN & Wifi & somehow internet becomes inaccessible, does automatic switchover
happens between LAN-> WIFI or vice versa.

Developer technologies | Universal Windows Platform (UWP)
Developer technologies | C++
0 comments No comments
{count} votes

2 answers

Sort by: Most helpful
  1. Anonymous
    2021-12-09T03:17:52.447+00:00

    Hello,

    Welcome to Microsoft Q&A!

    You could take a look at the NetworkInformation Class. You could use this class to access network connection information for the local machine. It contains a NetworkStatusChanged Event that occurs when the network status changes for a connection. You could check the connection profile in the event to check if the network is wifi or mobile or LAN, check if the network is available.

    The code looks like this:

     private NetworkStatusChangedEventHandler networkStatusCallback;  
     private Boolean registeredNetworkStatusNotif;  
    
            void NetworkStatusChange()  
            {  
                // register for network status change notifications  
                try  
                {  
                    networkStatusCallback = new NetworkStatusChangedEventHandler(OnNetworkStatusChange);  
                    if (!registeredNetworkStatusNotif)  
                    {  
                        NetworkInformation.NetworkStatusChanged += networkStatusCallback;  
                        registeredNetworkStatusNotif = true;  
                    }  
                }  
                catch (Exception ex)  
                {  
                     
                }  
            }  
      
            public async void OnNetworkStatusChange(object sender)  
            {  
                try  
                {  
                    // get the ConnectionProfile that is currently used to connect to the Internet                  
                    ConnectionProfile InternetConnectionProfile = NetworkInformation.GetInternetConnectionProfile();  
      
                    if (InternetConnectionProfile == null)  
                    {  
                     // not connect  
                    }  
                    else  
                    {  
                        // check if it is WiFi or it is mobile. otherwise it is LAN  
                        bool isWLANConnection = (InternetConnectionProfile == null) ? false : InternetConnectionProfile.IsWlanConnectionProfile;  
      
                        bool isWWANConnection = (InternetConnectionProfile == null) ? false : InternetConnectionProfile.IsWwanConnectionProfile;  
                        // check if network is enabled  
                        bool isInternetConnected = NetworkInterface.GetIsNetworkAvailable();  
                    }  
                      
                }  
                catch (Exception ex)  
                {  
                     
                }  
            }  
    

    You could refer to these documents for more information here: How to retrieve network connection information and How to manage network connection events and changes in availability.

    Thank you.


    If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".
    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

    1 person found this answer helpful.
    0 comments No comments

  2. Castorix31 90,686 Reputation points
    2021-12-06T13:33:24.837+00:00

    Connection/Disconnection events can be received with INetworkListManagerEvents

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.