I'm trying to create a PS script that creates a Windows firewall rule, blocking the port "6672" for a certain .exe file on an INBOUND connection but lets me have the option to whitelist certain IPs.
The way to do this manually means I have to block the port (6672) for my .exe file completely to ALL IP's then add a range leaving out the IP's I want to whitelist.
For Example if I want to add "192.168.0.3" I have to set a range on the rule for "0.0.0.0" to "192.168.0.2" then another for "192.168.0.4" to "255.255.255.255". The reason I have to do it this was it that in Windows firewall it looks like you cannot whitelist single IP's from a block rule and block rules override any allow rules.
So back to my original point, I'm really struggling for ideas on how to resolve this at the moment as I can't find a workaround. Is there a way anybody knows of to be able to exclude certain IP's from a rule or how to make an allow rule be prioritised over a block rule?
So i have THIS CODE:
New-NetFirewallRule -DisplayName "GTAO" -Direction Inbound -LocalPort 6672 -Protocol UDP -Action Block New-NetFirewallRule -DisplayName "GTAO" -Direction Outbound -LocalPort 6672 -Protocol UDP -Action Block
I basically want something like this to override the previous rule creating a "whitelist" on this rule for individual IP's
$UIP = Read-Host "Enter IP to whitelist" New-NetFirewallRule -DisplayName "GTA$UIP" -Direction Inbound -LocalPort 6672 -Protocol UDP -Action Allow -RemoteAddress $UIP