How to block an IP or a Website using PowerShell in Windows 10

how to block an ip or a website using powershell in windows 10 - How to block an IP or a Website using PowerShell in Windows 10

PowerShell comes with a Netsecurity module that enables you to. You can use the operate — New-InternetFirewallRule — in Netsecurity to block an IP or a web site using PowerShell in Windows. The function permits you to create a new inbound or outbound firewall rule and provides the rule to the goal pc.

Block IP or Website using PowerShell

While blocking IP ranges work completely, blocking a web site or area is hard. That’s as a result of there will be a a number of IP connected to the area, and whilst you can stop them, the DNS resolver can work out a completely different IP each time it queries. Also, at instances, the identical IP could possibly be utilized by associated companies, and blocking that IP would imply blocking different companies as properly.

  1. Block native or web IP addresses
  2. Block web site or domains

You will want admin privileges to execute these.

1] Block IP or Range using PowerShell

Using this command, you should use a single IP handle or vary of IP addresses.  Execute the next command in

New-InternetFirewallRule -DisplayName "Block XYZ.com IP handle" -Direction Outbound –LocalPort Any -Protocol TCP -Action Block -RemoteAddress 146.185.220.zero/23

You can substitute Block XYZ.com IP handle with something you’ll be able to bear in mind or makes it simple to perceive everytime you look again at it. The IP handle talked about on the finish of the RemoteAddress possibility is what will likely be blocked. Any web site or service that resolves to that will likely be blocked. You can substitute the RemoteAddress possibility with the LocalAddress possibility if the IP is the native community IP handle.

Once the execution is full, you need to obtain a standing message as ” The rule was parsed efficiently from the shop. (65536)”.  Open Windows Firewall and examine if the entry is on the market. Once confirmed, you have to be in a position to add extra using PowerShell.

2] Block Website or Domain using PowerShell

Since the operate doesn’t help URL blocking, we have now two selections. First is to question all attainable IP of that area, and block them. The second is to discover identified official IP ranges and block them. The later has decrease possibilities of by chance blocking different companies in contrast to the previous. That stated, if blocking a area is important, you’ll be able to at all times use one other software program to block them.

Resolve-DnsName "fb.com"

Note the IP handle which we are going to use in the second technique

New-InternetFirewallRule -DisplayName "Block XYZ.com IP handle" -Direction Outbound –LocalPort Any -Protocol TCP -Action Block -RemoteAddress 146.185.220.zero/23

When I used this with YouTube, it didn’t work although direct IP was blocked. When I used it with Facebook, it labored. So if a web site will be resolved using a number of IP addresses, then this technique is not going to work.

Using PowerShell instructions are easy. If you ever used the command immediate, it’s nearly as good as that; I hope you had been in a position to block IP or a web site using PowerShell in Windows efficiently. Anytime you need to take away them, you are able to do so from Windows Firewall or use the Remove-InternetFirewallRule command.

  • Tags: ,

Leave a Comment