1 year ago
#273875
TrHH
How can I block IP addresses through Windows Firewall with C#
I have a C# application to block an website. And this is my code:
blsite.StartInfo.FileName = ("powershell.exe");
blsite.StartInfo.UseShellExecute = false;
blsite.StartInfo.Arguments = "New-NetFirewallRule -DisplayName 'Block-example_com' -Direction Outbound –LocalPort Any -Protocol Any -Action Block -RemoteAddress 93.184.216.34";
blsite.Start();
blsite.WaitForExit();
I have run it, but it didn't work, even though in Windows Defender Firewall showed my rule.
I tried removing that rule, and running the above command directly through powershell got the result that the page was blocked.
Sorry for my poor English
c#
powershell
command-line
windows-firewall
0 Answers
Your Answer