简体   繁体   English

为什么删除适配器的默认IP时DeleteIPAddress失败?

[英]Why does DeleteIPAddress fails when deleting the adapter's default IP?

I'm trying to write a program that will switch the selected adapter's IP on command. 我正在尝试编写一个程序,该命令将在命令中切换所选适配器的IP。

For that, i'm using the GetAdaptersInfo() function to get the adapter's Index and it's IP context, and then using that to delete the current IP (through DeleteIPAddress(context)). 为此,我正在使用GetAdaptersInfo()函数来获取适配器的索引及其IP上下文,然后使用它来删除当前IP(通过DeleteIPAddress(context))。

After that, the new IP would be inserted through AddIPAddress(). 之后,将通过AddIPAddress()插入新IP。

The problem is, the call to the DeleteIPAddress function fails when trying to delete the "default" IP (the one not set by AddIPAddress()) and calling AddIPAddress before deleting the old IP just leaves the adapter with two different simultaneous IPs. 问题是,尝试删除“默认” IP(未由AddIPAddress()设置的IP)并在删除旧IP之前调用AddIPAddress时,对DeleteIPAddress函数的调用失败,只是使适配器具有两个不同的同时IP。

The DeleteIPAddress function fails with error 31 (A device attached to the system is not functioning). DeleteIPAddress函数失败,并显示错误31(连接到系统的设备无法运行)。

Is there another way to sucessfully change the IP Address on an adapter? 有没有其他方法可以成功更改适配器上的IP地址? Is DeleteIPAddress actually usable without getting context from AddIPAddress? 在没有从AddIPAddress获取上下文的情况下,DeleteIPAddress实际上可用吗?

They say, DeleteIPAddress deletes address previously added by AddIPAddress :-) I had do some research by the interest and... 他们说,DeleteIPAddress删除以前由AddIPAddress添加的地址:-)我已经按兴趣进行了一些研究,并且...

There are undocumented SetAdapterIPAddress function. 有未记录的SetAdapterIPAddress函数。

DWORD SetAdapterIpAddress( char *pszAdapGUID,
                       DWORD dwDHCP,
                       DWORD dwIP,
                       DWORD dwMask,
                       DWORD dwGateway );

It may work or not :-) Also there are WMI interface. 它可能行不通:-)还有WMI界面。 See for Win32_NetworkAdapterConfiguration class. 请参见Win32_NetworkAdapterConfiguration类。 And there are a records in the windows registry for NIC IP address... Windows注册表中有一个记录,记录了NIC IP地址...

I think, the complexity are presence in Windows many "internal" configuration agents (DHCP, others..) and they all are the internal part of the OS and then as they manipulate an ip address, the other manipulations out of the control may break working of them. 我认为,复杂性在于Windows中存在许多“内部”配置代理(DHCP等),它们都是操作系统的内部组成部分,然后当他们操作ip地址时,其他无法控制的操作可能会中断他们的工作。 Also there are possibility to assign a static ip address in the Registry and it also should not be broken. 也有可能在注册表中分配一个静态IP地址,并且也不应该破坏它。 And then you really have DeleteIPAddress which you previously add... I think, it is intended for your own dynamic config agents... 然后,您确实有了先前添加的DeleteIPAddress ...我认为,它用于您自己的动态配置代理...

If you are not satisfied by work of other agents you should turn them off (instead of manipulating ip address out of the control)... Or control them by some specific API... Or set static IP... 如果您对其他代理的工作不满意,则应将其关闭(而不是通过控制来控制IP地址)...或通过某些特定的API控制它们...或设置静态IP ...

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM