I have an application written in C# that needs to retrieve information like IP address, subnet mask from a disconnected network adapter.
I've tried using various methods such as WMI and the .NET NetworkAdapter class but they don't return any useful data when the network adapter is disconnected. I'm pretty sure Windows keeps this information somewhere, since I can apply network settings using netsh and it appears correctly in the Control Panel.
One thing that worked for me in XP was to parse the output of the netsh
tool开发者_如何学JAVA and it would return information even for a disconnected adapter. However, this doesn't seem to 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?
NetworkChange.NetworkAddressChanged += new NetworkAddressChangedEventHandler(NetworkChange_NetworkAddressChanged);
and/or
HKEY_LOCAL_MACHINE\SYSTEM\ControlSet001\Control\Network\\{4D36E972-E325-11CE-BFC1-08002BE10318}\\*
- List Interfaces
and then
HKEY_LOCAL_MACHINE\SYSTEM\ControlSet001\Services\\*\Parameters\Tcpip
current settings parameters
if DHCP - ON then only NetworkChange.NetworkAddressChanged because current IP is impossible to define
精彩评论