Host is also blocked in firewall if action.firewall is true in BlockHost action
This commit is contained in:
parent
4a715091b7
commit
d986ccb16d
2 changed files with 37 additions and 7 deletions
31
cleanW10.ps1
31
cleanW10.ps1
|
@ -26,7 +26,6 @@ function BlockHost {
|
|||
[object]$params
|
||||
)
|
||||
if ( $params.ContainsKey('file') ) {
|
||||
|
||||
Foreach ($line in Get-Content $params.file ){ BlockHost -params @{host=$line} }
|
||||
}
|
||||
if ( $params.ContainsKey('host') -and $params.host -ne "" ) {
|
||||
|
@ -39,12 +38,38 @@ function BlockHost {
|
|||
Write-Host -ForegroundColor Yellow "already blocked "
|
||||
return
|
||||
}
|
||||
Write-Host -ForegroundColor Green "done"
|
||||
}
|
||||
catch {
|
||||
Write-Host -ForegroundColor Red "error"
|
||||
Write-Host -NoNewline -ForegroundColor Red "error`n`t"
|
||||
Write-Host -ForegroundColor DarkRed $Error[0].Exeption.Message
|
||||
return
|
||||
}
|
||||
Write-Host -ForegroundColor Green "done"
|
||||
if ( $params.ContainsKey('firewall') -and $params.firewall ) {
|
||||
BlockHostByIP $params.host
|
||||
}
|
||||
}
|
||||
else {
|
||||
Write-Host -ForegroundColor Red "`tError : No name or file for action $($MyInvocation.MyCommand.Name)"
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
function BlockHostByIP {
|
||||
param(
|
||||
[string]$hostname
|
||||
)
|
||||
$ip = [system.net.Dns]::GetHostAddresses($hostname)
|
||||
$rule = Get-NetFirewallAddressFilter | Where-Object { $_.RemoteAddress -eq $ip } -ErrorAction SilentlyContinue | Get-NetFirewallRule
|
||||
if ( $rule ) {
|
||||
write-host -ForegroundColor yellow "`t`tFW Rule exist : ($($rule.name))"
|
||||
}
|
||||
else {
|
||||
write-host -NoNewline -Foregroundcolor Green "`t`tFW block host.`n`t`t"
|
||||
FwBlockOutputIP @{
|
||||
ip=$ip,
|
||||
name=$hostname
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Reference in a new issue