11

How to enumerate all network interfaces currently available on the computer (including virtual, non-connected, loopback etc)?

I need to know their IP4/6, Mask, Gateway, DNS, WINS etc


Language: C++, WinAPI

System: Windows 2000 and higher (including Win7)

Andrew
  • 3,696
  • 3
  • 40
  • 71
  • 1
    Consider this question: http://stackoverflow.com/questions/3069082/porting-getifaddrs-to-win-xp – Steve-o Mar 08 '11 at 06:38

3 Answers3

10

It sounds like you want a combination of a few different functions.

To get a list of adapters with their IPv4 addresses/masks, associated WINS servers and DNS servers, you can use GetAdaptersInfo. To get IPv6 addresses, you can use GetAdaptersAddresses.

Depending on what is included in your "etc." you might also want GetIfTable and GetIfEntry. GetIfTable gets a list of network adapters. GetIfEntry gets you information about each. These retrieve things like the amount of data that's been transmitted/retrieved over a particular interface. There's also a GetIfTable2/GetIfEntry2 that are only for Vista and newer that get more information.

If memory serves, GetIfTable/GetIfEntry list all the interfaces in the machine. GetAdaptersInfo only works with the "real" adapters.

Jerry Coffin
  • 476,176
  • 80
  • 629
  • 1,111
7

Have a look at http://www.codeproject.com/KB/IP/netcfg.aspx. It's a giant example of what you want to do.

bmargulies
  • 97,814
  • 39
  • 186
  • 310
6

Perversely you can use getaddrinfo ("..localmachine") to enumerate interfaces on Windows 2003+.

http://msdn.microsoft.com/en-us/library/ms738520(v=vs.85).aspx

Windows 7 with Service Pack 1 (SP1) and Windows Server 2008 R2 with Service Pack 1 (SP1) add support to hide interfaces.

http://support.microsoft.com/kb/2386184

Steve-o
  • 12,678
  • 2
  • 41
  • 60