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.
Asked
Active
Viewed 780 times
1 Answers
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!
-
1Good 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