Created
March 29, 2024 01:37
-
-
Save WindyNova/122bcaa1c6869bc6a03cfec3e2018916 to your computer and use it in GitHub Desktop.
Block dem ips
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # Copyleft Abel lolz | |
| if (-NOT ([Security.Principal.WindowsPrincipal][Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole([Security.Principal.WindowsBuiltInRole] "Administrator")) { | |
| # If not running as Administrator, re-launch the script with elevated permissions | |
| $CommandLine = "-File `"" + $MyInvocation.MyCommand.Path + "`" " + $MyInvocation.UnboundArguments | |
| Start-Process -FilePath PowerShell.exe -Verb Runas -ArgumentList $CommandLine | |
| Exit | |
| } | |
| # Define the list of applications to block | |
| $appsToBlock = @( | |
| @{ | |
| "Path" = "C:\Path\To\Your\Heart.exe"; | |
| "DisplayName" = "Lulz" | |
| } | |
| # Add more applications as needed | |
| ) | |
| $ipRangesFileUrl = "https://raw.githubusercontent.com/elemen3/wepn/master/china_ip_ranges.txt" | |
| # Function to fetch IP ranges from the online file | |
| function Get-IPRanges { | |
| $ipRangesContent = Invoke-WebRequest -Uri $ipRangesFileUrl | |
| return $ipRangesContent.Content -split "`n" | |
| } | |
| # Function to update or delete existing firewall rules | |
| function Update-FirewallRules { | |
| $ipRanges = Get-IPRanges | |
| foreach ($app in $appsToBlock) { | |
| # Get existing rules for the application | |
| $existingRules = Get-NetFirewallRule -DisplayName "$($app.DisplayName)_*" | |
| foreach ($rule in $existingRules) { | |
| # Check if the rule's IP range is still in the new list | |
| if ($ipRanges -contains $rule.RemoteAddress) { | |
| # Rule still needed, no action required | |
| } else { | |
| # Rule no longer needed, delete it | |
| Remove-NetFirewallRule -DisplayName $rule.DisplayName | |
| } | |
| } | |
| # Create new rules for new IP ranges | |
| foreach ($ipRange in $ipRanges) { | |
| if ($ipRange -eq "") { continue } | |
| $ruleName = "$($app.DisplayName)_$ipRange" | |
| if (-not (Get-NetFirewallRule -DisplayName $ruleName -ErrorAction SilentlyContinue)) { | |
| New-NetFirewallRule -DisplayName $ruleName -Direction Outbound -Program $app.Path -Action Block -RemoteAddress $ipRange | |
| } | |
| } | |
| } | |
| } | |
| # Main script execution | |
| Update-FirewallRules |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment