Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Programmatically add IP to Server 2008 firewall rule

Anybody know how to programmatically add an IP address to a Server 2008 Windows Firewall with Advanced Security rule?

i.e. I've setup a Block Action firewall rule which has some IP addresses listed under the "Remote IP address" section of the Scope. I want to be able to programmatically add (or perhaps remove) IP addresses from this list. Are there .NET objects available to do this?

like image 570
Guy Avatar asked Dec 07 '10 23:12

Guy


People also ask

How do I allow a specific IP address in Windows Firewall?

Step 1) On the Start menu, Click 'Windows Firewall with Advanced Security'. Step 2) Click the 'Advanced settings' option in the sidebar. Step 3) On the left side, click the option 'Inbound Rules'. Step 4) On the right, under the section 'Actions', click on the option 'New Rule'.


2 Answers

The Windows Firewall with Advanced Security Start Page can be found at:

http://msdn.microsoft.com/en-us/library/ff956124(v=VS.85).aspx

Specifically, it seems you need the INetFwRule Interface which is described at:

http://msdn.microsoft.com/en-us/library/aa365344(v=VS.85).aspx

Check the get_RemoteAddresses and put_RemoteAddresses

like image 168
Thomas Langston Avatar answered Oct 15 '22 03:10

Thomas Langston


You can also try the netsh environment.
I used it once for changing the MTU of my interface

like image 21
athspk Avatar answered Oct 15 '22 04:10

athspk