1

Does anyone know how to remove an IP Address alias in Windows (7, 8, 10) using C#? There's plenty of code out there showing how to add an IP address using "InvokeMethod("EnableStatic", newIP, null);" but I haven't found a way to remove an alias IP Address if one or more have been added to a network interface.

Pungo120
  • 105
  • 1
  • 13

1 Answers1

1

I managed to do it using Netsh.exe on win7:

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();

Got the idea from this answer: https://stackoverflow.com/a/18400554/4172861

You might need to run your code under Admin permission. I hope this helps you, Good luck!

Community
  • 1
  • 1
TBD
  • 509
  • 7
  • 15
  • 1
    Good thinking! It's been a while since I originally asked this question and I'm not sure I ever even considered using netsh via the Process class. – Pungo120 May 11 '17 at 14:57