CommandLine IP block / unblock in Windows Firewall with Advanced Security

孤街浪徒 提交于 2019-12-10 19:51:06

问题


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.


回答1:


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




回答2:


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.



来源:https://stackoverflow.com/questions/4477079/commandline-ip-block-unblock-in-windows-firewall-with-advanced-security

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!