diff --git a/cleanW10.ps1 b/cleanW10.ps1 index f5265d5..16bd400 100755 --- a/cleanW10.ps1 +++ b/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 + } } } diff --git a/modules.d/BlockHosts.conf b/modules.d/BlockHosts.conf index 1909b97..195bd0f 100644 --- a/modules.d/BlockHosts.conf +++ b/modules.d/BlockHosts.conf @@ -4,8 +4,13 @@ "actions" : [ { "action" : "BlockHost", - "file" : "hosts.txt", - "host" : "" - } + "file" : "base.txt", + "host" : "", + "firewall" : true + }, + { + "action" : "BlockHost", + "file" : "ms-skype-messeger.txt" + } ] -} \ No newline at end of file +}