Revert to Resolve-DnsName in BlockHostByIP(), File in BlockHost() can use comment
This commit is contained in:
parent
6151c51531
commit
97b826a915
1 changed files with 10 additions and 9 deletions
17
cleanW10.ps1
17
cleanW10.ps1
|
@ -26,7 +26,7 @@ function BlockHost {
|
|||
[object]$params
|
||||
)
|
||||
if ( $params.ContainsKey('file') ) {
|
||||
Foreach ($line in Get-Content $params.file ){ BlockHost -params @{host=$line;firewall=$params.firewall} }
|
||||
Get-Content $params.file | where { $_ -notmatch "^#.*$|^$" } | Foreach{ BlockHost -params @{host=$_;firewall=$params.firewall} }
|
||||
}
|
||||
elseif ( $params.ContainsKey('host') -and $params.host -ne "" ) {
|
||||
Write-Host "`n`tBlock host $($params.host) : "
|
||||
|
@ -63,12 +63,12 @@ function BlockHostByIP {
|
|||
param(
|
||||
[string]$hostname
|
||||
)
|
||||
$resolv = [system.net.Dns]::GetHostAddresses($hostname) | Select IPAddressToString
|
||||
#$resolv = Resolve-DnsName $hostname -ErrorAction SilentlyContinue | select Address,Type | Where { $_.type -match "^A{1,4}$" }
|
||||
#$resolv = [system.net.Dns]::GetHostAddresses($hostname) | Select IPAddressToString
|
||||
$resolv = Resolve-DnsName $hostname -ErrorAction SilentlyContinue | Where { $_.type -match "^A{1,4}$" } | select Address
|
||||
$resolv | Foreach {
|
||||
Write-Host -NoNewLine "`t"
|
||||
$ip = $_.IPAddressToString
|
||||
Write-Debug "Found a valid IP $($_.IPAddressToString)"
|
||||
$ip = $_.Address
|
||||
Write-Debug "Found a valid IP $ip"
|
||||
$rule = Get-NetFirewallAddressFilter | Where-Object { $_.RemoteAddress -eq $ip } | Get-NetFirewallRule
|
||||
if ( $rule ) {
|
||||
write-host -NoNewLine "`tFW Rule exist : "
|
||||
|
@ -108,9 +108,10 @@ function FwBlockOutputIP {
|
|||
$name = $FW_RULE_NAME_PREFIX + "_IP_" + $params.name + "-" + $params.ip
|
||||
}
|
||||
Write-Host -NoNewline "`tAdd FW IP rule $name ($($params.ip)) : "
|
||||
if ( Get-NetFirewallRule -Name $name -ErrorAction SilentlyContinue) {
|
||||
Write-Host -ForegroundColor Yellow "already exist"
|
||||
return
|
||||
$rule = Get-NetFirewallAddressFilter | Where-Object { $_.RemoteAddress -eq $params.ip } | Get-NetFirewallRule
|
||||
if ( $rule ) {
|
||||
write-host -NoNewLine " exist : "
|
||||
write-host -ForegroundColor yellow $rule.name
|
||||
}
|
||||
else {
|
||||
Try {
|
||||
|
|
Reference in a new issue