Programmatically retrieve information about a disabled network adapter in .NET.

I have an application written in C # that should extract information such as IP address, subnet mask from a disconnected network adapter.

I tried using various methods such as WMI and the .NET NetworkAdapter class, but they do not return useful data when disconnecting the network adapter. I am sure Windows stores this information somewhere, since I can apply network settings using netsh and it displays correctly on the control panel.

One thing that worked for me in XP was to analyze the output of the tool netsh, and it returned information even for a disconnected adapter. However, this does not work on Windows 7.

Win XP output:

Configuration for interface "Local Area Connection 5"
    DHCP enabled:                         No
    IP Address:                           169.254.0.128
    SubnetMask:                           255.255.255.0
    InterfaceMetric:                      0

Win7 Output:

Configuration for interface "Local Area Connection 2"
    DHCP enabled:                         No
    InterfaceMetric:                      5

Any ideas?

+3
1
NetworkChange.NetworkAddressChanged += new NetworkAddressChangedEventHandler(NetworkChange_NetworkAddressChanged);

/

HKEY_LOCAL_MACHINE\SYSTEM\ControlSet001\Control\Network\\{4D36E972-E325-11CE-BFC1-08002BE10318}\\*
- List Interfaces

HKEY_LOCAL_MACHINE\SYSTEM\ControlSet001\Services\\*\Parameters\Tcpip
current settings parameters 

DHCP - ON, NetworkChange.NetworkAddressChanged, IP

+1

Source: https://habr.com/ru/post/1737757/


All Articles