【问题标题】:Remove IP Address Alias Using C#使用 C# 删除 IP 地址别名
【发布时间】:2017-06-16 04:50:46
【问题描述】:

有谁知道如何使用 C# 在 Windows(7、8、10)中删除 IP 地址别名?有很多代码展示了如何使用“InvokeMethod("EnableStatic", newIP, null);" 添加 IP 地址但如果一个或多个已添加到网络接口,我还没有找到删除别名 IP 地址的方法。

【问题讨论】:

    标签: c# network-programming ip


    【解决方案1】:

    我设法在 win7 上使用 Netsh.exe 做到了:

    string requestedInterface = "Loopback"; //the interface from which you want to remove the ip
    string requestedIP = "111.111.111.111"; //the ip you wish to remove from requestedInterface 
    
    Process proc = new Process(); //using System.Diagnostics
    proc.StartInfo.FileName = "netsh.exe"
    proc.StartInfo.Arguments = "interface ip delete address name=\"" + requestedInterface + "\" " + requestedIP ;
    proc.StartInfo.UseShellExecute = false;
    proc.StartInfo.RedirectStandardOutput = true;
    proc.start();
    

    从这个答案中得到了想法: https://stackoverflow.com/a/18400554/4172861

    您可能需要在管理员权限下运行您的代码。 希望对你有帮助,祝你好运!

    【讨论】:

    • 好主意!自从我最初提出这个问题以来已经有一段时间了,我不确定我是否曾经考虑过通过 Process 类使用 netsh。
    猜你喜欢
    • 1970-01-01
    • 2012-04-14
    • 2020-12-13
    • 2018-02-15
    • 1970-01-01
    • 2018-10-28
    • 2012-11-14
    • 1970-01-01
    • 2021-03-28
    相关资源
    最近更新 更多