How to retrive network category(public or private) programmatically in c#?

Joshi, Aparna 1 Reputation point
2021-11-25T12:26:21.763+00:00

in Control Panel -> Network and Sharing Center, there is a network category or type we can see (Public or Private).

is there any C# API available to get that value?

I have attached an image and highlighted the data I am looking for.

Thank you.

152557-capture.png

Windows API - Win32
Windows API - Win32
A core set of Windows application programming interfaces (APIs) for desktop and server applications. Previously known as Win32 API.
2,736 questions
{count} votes

3 answers

Sort by: Most helpful
  1. RLWA32 47,221 Reputation points
    2021-11-25T13:05:05.613+00:00
    1 person found this answer helpful.
    0 comments No comments

  2. Castorix31 86,986 Reputation points
    2021-11-25T13:49:09.51+00:00

    In UWP, you get Network information with

    using Windows.Networking.Connectivity;
    

    Something like :

    IReadOnlyList<ConnectionProfile> profiles = NetworkInformation.GetConnectionProfiles();
    foreach (var profile in profiles)
    {                       
        NetworkAdapter na = profile.NetworkAdapter;
        NetworkTypes nt = na.NetworkItem.GetNetworkTypes();
        NetworkConnectivityLevel ncl = profile.GetNetworkConnectivityLevel();
        System.Diagnostics.Debug.WriteLine("Name {0} - Type : {1} - {2}", profile.ProfileName, nt, ncl);                      
    }
    
    1 person found this answer helpful.
    0 comments No comments

  3. josiah Markus Danbinta 1 Reputation point
    2021-11-25T13:52:59.177+00:00

    Using the search option will help

    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.