Julien Choplin

Hi!

I've got a nice subject to work on but I can't find anything to help me.
I would like to determine my network location type on my laptop (domain, public, private) and get a few information on the active networks connections. So i think i have to use the NLA API but i haven't been able to manage all these structures and methods in c#.

Can someone help me please

Regards

Julien Choplin



Re: Visual C# General Network Awareness Location on Windows Vista (C#)

AlexBB

Hi Julien,

Try this. I copied it from MSDN somewhere but cannot recall now where from.

using System;

using System.Net;

using System.Net.Security;

using System.Net.NetworkInformation;

namespace Examples.Net.AddressChanges

{

public class NetworkingMonitor

{

public static void Networking( )

{

if (NetworkInterface.GetIsNetworkAvailable ( ) == true)

{

Console.WriteLine ( "Network Is Avalable" );

}

else

{

Console.WriteLine ( "Network Is NOT Avalable" );

}

NetworkChange.NetworkAddressChanged += new

NetworkAddressChangedEventHandler ( AddressChangedCallback );

}

static void AddressChangedCallback( object sender, EventArgs e )

{

NetworkInterface[] adapters = NetworkInterface.GetAllNetworkInterfaces ( );

foreach (NetworkInterface n in adapters)

{

Console.WriteLine ( "Name: {0} ID: {1}, Operational Status: {2}",

n.Name, n.Id, n.OperationalStatus );

}

}

} // NetworkingMonitor

}

You will see many methods in NetworkInterface, like this one (also from MSDN):

public static void DisplayMulticastAddresses( )

{

Console.WriteLine ( "Multicast Addresses" );

NetworkInterface[] adapters = NetworkInterface.GetAllNetworkInterfaces ( );

foreach (NetworkInterface adapter in adapters)

{

IPInterfaceProperties adapterProperties = adapter.GetIPProperties ( );

MulticastIPAddressInformationCollection multiCast = adapterProperties.MulticastAddresses;

if (multiCast.Count > 0)

{

Console.WriteLine ( adapter.Description );

foreach (IPAddressInformation multi in multiCast)

{

Console.WriteLine ( " Multicast Address ....................... : {0} {1} {2}",

multi.Address,

multi.IsTransient "Transient" : "",

multi.IsDnsEligible "DNS Eligible" : ""

);

}

Console.WriteLine ( );

}

}

} // DisplayMulticastAddresses

Good luck






Re: Visual C# General Network Awareness Location on Windows Vista (C#)

AlexBB

Julien Choplin wrote:
Hi!

I've got a nice subject to work on but I can't find anything to help me.
I would like to determine my network location type on my laptop (domain, public, private) and get a few information on the active networks connections. So i think i have to use the NLA API but i haven't been able to manage all these structures and methods in c#.

Can someone help me please

Regards

Julien Choplin

Also try windows\system32\netstat.exe






Re: Visual C# General Network Awareness Location on Windows Vista (C#)

Julien Choplin

Thanks a lot! It really helped me, but only to find a workaround Smile

In fact, with these namespaces (System.Net.Security and System.Net.NetworkInformation), i can't find if i'm in one of the three location types given by windows vista (Domain Profile, Private Profile, and Public Profile). Have you got more informations about it do you know how i can detect it





Re: Visual C# General Network Awareness Location on Windows Vista (C#)

AlexBB

i can't find if i'm in one of the three location types given by windows vista (Domain Profile, Private Profile, and Public Profile)

I think you can find it in Control Panel==>Network And Internet==>Network Sharing Center.

And I think you are in Private Network by default. As far as the domain, it is my understanding it defaults to you computer name but you can set it up differently, if you have a domain name registered to your name. Perhaps somebody else will comment on this issue also.






Re: Visual C# General Network Awareness Location on Windows Vista (C#)

Julien Choplin

mmm, i'm not that dumb. thanks.

i want to know it programmatically........ so this don't help me.