Question

I'd like to programmatically be able to block outgoing packets to some IPs. Nevermind the application, I would like to be able to do it.

I have Windows 7 x64 Professional so it comes with WindowsFirewall with Advanced Security which has an outbound filter capability.

Currently I'm manually adding rules to block an IP, but there has got to be a better way.

I read this: Any way to turn the "internet off" in windows using c#? and http://msdn.microsoft.com/en-us/library/bb945065.aspx so I know it's possible to write such applications.

I'm a java programmer, and I couldn't find an jni to interface with firewall.dll. I don't know anything about C# to write one myself.

I'm asking if there a - there's a tool out there that can do this, please let me know about it. I've Googled and Googled, but alas - nothing. If there isn't please get me started on how to write it myself.

In case you're feeling generous, you could write one for me s.t. you could block outbound traffic to an IP and unblock it.

Thank you all very much.

Was it helpful?

Solution

The most straightforward way would be just to run netsh, here's an article on how to do it

OTHER TIPS

A modern alternative to netsh is powershell. The commands Enable-NetFirewallRule and Disable-NetFirewallRule allow you to turn rules on/off from a powershell script. The command Set-NetFirewallRule allows you to edit an existing firewall rule, for if you want to change the ip address a rule is affecting. You could even add new rules using New-NetFirewallRule as well if needed.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top