Skip to content

Commit

Permalink
Updated script to handle Sub-TLDs
Browse files Browse the repository at this point in the history
  • Loading branch information
HotCakeX committed Sep 20, 2023
2 parents e2ad86f + fba9960 commit 2184aa2
Showing 1 changed file with 24 additions and 8 deletions.
32 changes: 24 additions & 8 deletions NextDNS API/Stream the logs - Customized Output for Microsoft.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -127,12 +127,26 @@ try {
# Sometimes it identifies sub-domains as root domains, so here we make sure it doesn't happen
# first see if the root domain has more than 1 dot in it, indicating that it contains sub-domains
if ($Log.root -like '*.*.*') {
# Define a regex pattern that starting from the end, captures everything until the 2nd dot
# Define a regex pattern that starts from the end (rightmost side), captures everything until the 2nd dot (goes towards the left)
if ($Log.root -match '(?s).*\.(.+?\..+?)$') {

$RootDomain = $matches[1]

Write-Host "$RootDomain is Regex cleared" -ForegroundColor Yellow

# Assign the regex matches to a custom variable because there will be a 2nd $matches variable later and we don't want it to be overwritten
$Possibility = $matches

# If NextDNS didn't properly provide the correct root domain, check if it contains any of these sub-TLDs
# If it does then select the entire string
if ($Possibility[1] -match '(?<SubTLD>co|ac|com|t|uk|eu|app|org|net)[.](?<TLD>.*)$') {

$RootDomain = $Possibility[0]

Write-Host "Sub-TLD detected in $RootDomain, applying the appropriate filters." -ForegroundColor Magenta
}

else {
$RootDomain = $Possibility[1]

Write-Host "$RootDomain is Regex cleared" -ForegroundColor Yellow
}
}
}

Expand All @@ -141,15 +155,17 @@ try {
$RootDomain = $Log.root

Write-Host "$RootDomain is OK" -ForegroundColor Magenta
}

}
# If the root domain's name resembles Microsoft domain names
if ($RootDomain -like '*msft*' `
-or $RootDomain -like '*microsoft*' `
-or $RootDomain -like '*bing*' `
-or $RootDomain -like '*xbox*' `
-or $RootDomain -like '*azure*' `
-or $RootDomain -like '*.ms*'
-or $RootDomain -like '*.ms*' `
-or $RootDomain -like '*.msn*' `
-or $RootDomain -like '*edge*'
) {
# If the domain that resembles Microsoft domain was blocked
if ($Log.status -eq 'blocked') {
Expand Down

0 comments on commit 2184aa2

Please sign in to comment.