How could I get or change the IP address of a disconnected NIC in Windows?

僤鯓⒐⒋嵵緔 提交于 2019-12-14 02:22:37

问题


I have configured the IP address for a NIC successfully in Windows7. But after pulling out the net cable, I can't get the IP address from API and ipconfig, but I can view it in "Network Connections". And if I insert the cable again, then I can get the address once more.

How could I get or change the IP address of a NIC, when the NIC is disconnected? I have used "GetAdaptersInfo" "GetIpAddrTable" or WMI class. All above method return 0.0.0.0 ipaddress for such NIC.

My platform is Windows7, and I wish the method can work for other Windows platforms.

Thanks!


回答1:


To get the IP from a disconnected NIC, try using netsh interface dump, for example:

netsh interface ipv4 dump name="Wireless Network Connection"

The ouput is like:

#----------------------------------
# IPv4 Configuration
# ----------------------------------

pushd interface ipv4

reset
set global icmpredirects=enabled
add address name="Wireless Network Connection" address=192.168.229.2 mask=255.255.255.0


popd
# End of IPv4 configuration



回答2:


The IP address isn't a property inherent to the NIC. The instant it becomes disconnected, it loses its IP. The IP is assigned by either a DHCP server or statically by your OS when there is actually a connection.




回答3:


Some people suggested me to change a registry key, which will turn off media detection.

HKEY_LOCAL_MACHINE\System\CurrentControlSet\Services\Tcpip\Parameters\DisableDHCPMediaSense

Type:  REG_DWORD
Value: 1

I have tested this method but it still returns 0.0.0.0, but I can read unpluged NIC's IP address from reg:

[HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\services\[NIC_GUID]}\Parameters\Tcpip]
EnableDHCP
IPAddress
SubnetMask
DefaultGateway


来源:https://stackoverflow.com/questions/6594523/how-could-i-get-or-change-the-ip-address-of-a-disconnected-nic-in-windows

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!