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
|
[object]$params
|
||||||
)
|
)
|
||||||
if ( $params.ContainsKey('file') ) {
|
if ( $params.ContainsKey('file') ) {
|
||||||
|
|
||||||
Foreach ($line in Get-Content $params.file ){ BlockHost -params @{host=$line} }
|
Foreach ($line in Get-Content $params.file ){ BlockHost -params @{host=$line} }
|
||||||
}
|
}
|
||||||
if ( $params.ContainsKey('host') -and $params.host -ne "" ) {
|
if ( $params.ContainsKey('host') -and $params.host -ne "" ) {
|
||||||
|
@ -39,12 +38,38 @@ function BlockHost {
|
||||||
Write-Host -ForegroundColor Yellow "already blocked "
|
Write-Host -ForegroundColor Yellow "already blocked "
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
Write-Host -ForegroundColor Green "done"
|
||||||
}
|
}
|
||||||
catch {
|
catch {
|
||||||
Write-Host -ForegroundColor Red "error"
|
Write-Host -NoNewline -ForegroundColor Red "error`n`t"
|
||||||
|
Write-Host -ForegroundColor DarkRed $Error[0].Exeption.Message
|
||||||
return
|
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
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -4,8 +4,13 @@
|
||||||
"actions" : [
|
"actions" : [
|
||||||
{
|
{
|
||||||
"action" : "BlockHost",
|
"action" : "BlockHost",
|
||||||
"file" : "hosts.txt",
|
"file" : "base.txt",
|
||||||
"host" : ""
|
"host" : "",
|
||||||
|
"firewall" : true
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"action" : "BlockHost",
|
||||||
|
"file" : "ms-skype-messeger.txt"
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
}
|
}
|
Reference in a new issue