Search code examples
c#portwindows-firewallip-restrictions

How can I create a program to dynamically add/remove IP that can access a port to a 3rd party service?


I would like to be able to use c# to create a Whitelist (or remove from the list) IPs that are allowed to access a particular port, ranges of ports, or any port at all to a third party service on a Windows 2012 server.

Is there a way that I can programmatically control access to another service?


Solution

  • In Windows, it is possible to access network commands using powershell and the netsh executable.

    Using C#, it is therefore possible to modify the firewall rules by using the System.Diagnostics.Process class and passing commands to this executable in the manners outlined in these two pages:

    How to use the Process class to call netsh has already been answered in the following post: Command netsh using C#