Windows 10: Broken script for blocking IP addresses in firewall rule.

Discus and support Broken script for blocking IP addresses in firewall rule. in Windows 10 Software and Apps to solve the problem; Hi there, I am trying to run a powershell script that I got using chat gpt. The script is supposed to block a range of ip addresses from a text... Discussion in 'Windows 10 Software and Apps' started by Windows Category - All, Apr 16, 2024.

  1. Broken script for blocking IP addresses in firewall rule.


    Hi there, I am trying to run a powershell script that I got using chat gpt. The script is supposed to block a range of ip addresses from a text document and create a block rule in windows defender firewall.The script runs it and creates the rule, but the rule has no details on it. The rule does not have the IP addresses in it and it does not have the specified program I want to block.# Specify the path to the program executable$ProgramPath = "C:\Program Files x86\Call of Duty\_retail_\cod.exe"# Specify the path to the merged text document containing IP address ranges for multiple countries$M

    :)
     
    Windows Category - All, Apr 16, 2024
    #1
  2. mike1127 Win User

    firewall rule to block addresses NOT on an IP list?


    I am just starting to learn the Windows Firewall (working on both Windows 7 and 10) and I'm not impressed with the inflexibility of its rules. I would like to know if


    1. Is there is a way to do what I want with Windows Firewall?
    2. Is there is a third-party firewall that would do it?


    What I want to do is create a rule that blocks outgoing connections, for program X, that are to a destination **NOT** in an IP list.


    Windows Firewall is not very flexible in how you specify IP list rules. When you give an IP list, your rule will match that list... you can't say "trigger the rule for non-matching IP addresses." Therefore to allow outgoing connections to a list, you have to


    1. Change the entire firewall policy to block outgoing connections by default so that you can create an "allow rule" matching your list. This will mess up the rest of your programs.


    2. Somehow combine a block rule and allow rule. Create a block rule for most traffic, with the "allow" rule overriding it when appropriate. However, this doesn't appear to be possible in general. It **may** be possible for connections that use IPSec, I'm not sure. And I'm not sure if I can use IPSec in my application.

    And is there a third-party firewall that can do it? Most 3rd-party firewalls are LESS sophisticated than Windows Firewall, because the use case they are addressing is providing an interface that doesn't require much comprehension. I need one that's actually MORE sophisticated than Windows Firewall.
     
    mike1127, Apr 16, 2024
    #2
  3. how do i add multiple ip addresses to be blocked into windows 11 firewall all at once

    Hi: In your script is there a limit to how many ip addresses that can be specified in that command line?

    Also, what changes to the script is necessary to read the ip addresses to be blocked from a file?
     
    SpinnerFamily, Apr 16, 2024
    #3
  4. Bill.Th Win User

    Broken script for blocking IP addresses in firewall rule.

    how do i add multiple ip addresses to be blocked into windows 11 firewall all at once

    Hi SpinnerFamily,

    I am Bill, an Independent Advisor. I am here to help.

    You can use PowerShell to add multiple IP addresses to firewall. Use this script:

    $name = Get-NetFirewallRule -DisplayName "Your Firewall Rule Name"

    $ips = @("192.168.1.150", "192.168.1.151") # Add your IP addresses here

    foreach ($r in $name) {

    Set-NetFirewallRule -DisplayName $r.DisplayName -RemoteAddress $ips

    }

    Note:

    Replace "Your Firewall Rule Name" with the name of your firewall rule.

    Replace the IP addresses in the $ips array with the IP addresses you want to block.

    This script gets the firewall rule using its display name, then sets the remote addresses for that rule to the list of IP addresses you specified.

    IP blocking can affect network communication.Always double-check the IP addresses you’re blocking to avoid unintended consequences.

    I hope this helps!
     
    Bill.Th, Apr 16, 2024
    #4
Thema:

Broken script for blocking IP addresses in firewall rule.

Loading...
  1. Broken script for blocking IP addresses in firewall rule. - Similar Threads - Broken script blocking

  2. Broken script for blocking IP addresses in firewall rule.

    in Windows 10 Gaming
    Broken script for blocking IP addresses in firewall rule.: Hi there, I am trying to run a powershell script that I got using chat gpt. The script is supposed to block a range of ip addresses from a text document and create a block rule in windows defender firewall.The script runs it and creates the rule, but the rule has no details...
  3. Is it possible to add IP address in the firewall rule via GPO through Powershell

    in Windows 10 Gaming
    Is it possible to add IP address in the firewall rule via GPO through Powershell: Hi Experts,Is there any possible way to add an IP address in the firewall rule via GPO through PowerShell? I have searched on the internet I am not able to find any relevant link.If its possible could someone please let me know how to do that ?I have attached the relevant...
  4. Is it possible to add IP address in the firewall rule via GPO through Powershell

    in Windows 10 Software and Apps
    Is it possible to add IP address in the firewall rule via GPO through Powershell: Hi Experts,Is there any possible way to add an IP address in the firewall rule via GPO through PowerShell? I have searched on the internet I am not able to find any relevant link.If its possible could someone please let me know how to do that ?I have attached the relevant...
  5. Hello, I've created firewall rules to block several remote ip addresses for inbound...

    in Windows 10 Gaming
    Hello, I've created firewall rules to block several remote ip addresses for inbound...: Hello, I've created firewall rules to block several remote ip addresses for inbound connections. Windows defender firewall 11 seems to be ignoring my custom firewall rules, and I ma still receiving junk & porn gmails from these ip addresses. I've created a new custom rule and...
  6. Hello, I've created firewall rules to block several remote ip addresses for inbound...

    in Windows 10 Software and Apps
    Hello, I've created firewall rules to block several remote ip addresses for inbound...: Hello, I've created firewall rules to block several remote ip addresses for inbound connections. Windows defender firewall 11 seems to be ignoring my custom firewall rules, and I ma still receiving junk & porn gmails from these ip addresses. I've created a new custom rule and...
  7. Can i exclude set of IP Address range from the Windows Firewall Rule?

    in Windows 10 Software and Apps
    Can i exclude set of IP Address range from the Windows Firewall Rule?: Hi,I have configured some Windows Firewall outbound rules which are configured to block some ports on Windows 10 Machine.Want to know if I can exclude a range of IP addresses for a Windows Firewall rule? It seems that kind of feature is not available with the Windows...
  8. Can i exclude set of IP Address range from the Windows Firewall Rule?

    in Windows 10 Network and Sharing
    Can i exclude set of IP Address range from the Windows Firewall Rule?: Hi,I have configured some Windows Firewall outbound rules which are configured to block some ports on Windows 10 Machine.Want to know if I can exclude a range of IP addresses for a Windows Firewall rule? It seems that kind of feature is not available with the Windows...
  9. Inbound Firewall Rule that Blocks

    in Windows 10 Customization
    Inbound Firewall Rule that Blocks: Please help me understand how the 2 Inbound Rules created by MMC actually operate. Action, Enabled, Service, Program, Protocol Block, Yes, Any, C:\windows\system32\mmc.exe, TCP Block, Yes, Any, C:\windows\system32\mmc.exe, UDP If these...
  10. firewall rule to block addresses NOT on an IP list?

    in Windows 10 Network and Sharing
    firewall rule to block addresses NOT on an IP list?: I am just starting to learn the Windows Firewall (working on both Windows 7 and 10) and I'm not impressed with the inflexibility of its rules. I would like to know if 1. Is there is a way to do what I want with Windows Firewall? 2. Is there is a third-party firewall...