我试着用这个函数编写添加ip地址的程序
DWORD AddIPAddress(
__in IPAddr Address,
__in IPMask IpMask,
__in DWORD IfIndex,
__out PULONG NTEContext,
__out PULONG NTEInstance
);
我添加了,但是怎么删除呢。 DeleteIPAddress 将 NTEContext 作为参数我如何在 MSDN 中获取它,他们写道它由 AddIPAddress 函数返回但是当我第二次使用相同的 ip 地址调用它时它返回错误 2. 怎么办?
我可以在cmd中使用Ipconfig命令查看添加的ip地址,可能还有其他方法可以手动查看或删除它
最佳答案
你不能这样做。来自 MSDN :
To use
DeleteIPAddress
,AddIPAddress
must first be called to get the handleNTEContext
. The previous procedure assumes thatAddIPAddress
has already been called somewhere in the code, andNTEContext
has been saved and remains uncorrupted.
添加地址的生命周期如图here :
The
AddIPAddress
function is used to add a new IPv4 address entry on a local computer. The IPv4 address added by theAddIPAddress
function is not persistent. The IPv4 address exists only as long as the adapter object exists. Restarting the computer destroys the IPv4 address, as does manually resetting the network interface card (NIC). Also, certain PnP events may destroy the address.
关于c++ - DeleteIPAddress 和 AddIpAddress 问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4147405/