Enumerating Network interfaces

46 views
Skip to first unread message

Ulrich Petri

unread,
Apr 16, 2001, 2:19:58 PM4/16/01
to
Hi all,

my question is how to enumerate the ip addresses of all installed Network
interfaces useing the .Net Framework
in plain Win32 i can write:
WSAIoctl(...) to get all the interface params.
How is this don with .Net i have searched through the System.Net Namespace
but found nothing.
PLease let me know if i'm missing something here or if it is (until now) not
possible with the Frameweork then how do i accomplish this with the old
windows api can i still call the Win32 API functions?

Thanks in advance.

Cu Ulrich


Ulrich Petri

unread,
Apr 16, 2001, 2:19:34 PM4/16/01
to

Willy.D

unread,
Apr 16, 2001, 4:26:08 PM4/16/01
to
Ulrich,
Maybe you can try to use the Management classes (WMI) if possible.
Sample:

using System.Management;
....
....
static void EnumNetworkAdapters() {
query = new ManagementObjectSearcher("SELECT * FROM
Win32_NetworkAdapterConfiguration") ;
ManagementObjectCollection queryCollection = query.Get();
foreach( ManagementObject mo in queryCollection ) {
Console.WriteLine( "'{0}’", mo.ClassPath);
Console.WriteLine( "'{0}’", mo.Options);
Console.WriteLine( "Index\t‘{0}’", mo["Index"]);
Console.WriteLine( "Description\t‘{0}’", mo["Description"]);
Console.WriteLine( "MacAddress\t‘{0}’", mo["MacAddress"]);
if((bool)mo["IPEnabled"] == true) {
string[] addresses = (string[])mo["IPAddress"];
string[] subnets = (string[])mo["IPSubnet"];
Console.WriteLine( "DNS Host\t‘{0}’", mo["DNSHostName"]);
Console.WriteLine( "DNS Domain\t‘{0}’", mo["DNSDomain"]);
foreach(string s in addresses) {
Console.WriteLine( "IP Address ‘{0}’", s);
}
foreach(string s in subnets) {
Console.WriteLine( "IP Subnet ‘{0}’", s);
}
}
}
}


Output (on system running W2K):

'\\SCENIC1\root\cimv2:Win32_NetworkAdapterConfiguration'
'System.Management.ObjectGetOptions'
Index '0'
Description 'Accton EN1207D/EN2242A Series NDIS 5.0 driver'
MacAddress '00:10:B5:81:B5:E1'
DNS Host 'scenic1'
DNS Domain 'pandora.be'
IP Address '192.168.0.2'
IP Subnet '255.255.255.0'

Willy.


"Ulrich Petri" <ul...@gmx.de> wrote in message
news:ut11CKqxAHA.1408@tkmsftngp05...

Ulrich Petri

unread,
Apr 16, 2001, 7:15:10 PM4/16/01
to

"Willy.D" <willy.d...@pandora.be> schrieb im Newsbeitrag
news:eeeD$NrxAHA.2188@tkmsftngp02...

Thank You!

After converting it to VB.Net it works great for me!

Greets Ulrich


@sihlnet.ch Pius Fässler

unread,
May 9, 2001, 3:20:19 PM5/9/01
to
Hello Ulrich
I saw that you converted the sample to vb. I did the same. Properties are
nice to read, but do you know how to set a property? What are the
properties of the function SetPropertyValue?
Thanks
"Ulrich Petri" <ul...@gmx.de> schrieb im Newsbeitrag
news:OcVJAvsxAHA.2068@tkmsftngp05...
Reply all
Reply to author
Forward
0 new messages