Skip to content

Instantly share code, notes, and snippets.

@poiriersimon
Created January 31, 2019 16:58
Show Gist options
  • Save poiriersimon/a444a41476ed2f441872373e84d92c50 to your computer and use it in GitHub Desktop.
Save poiriersimon/a444a41476ed2f441872373e84d92c50 to your computer and use it in GitHub Desktop.
Check if some IP or ip range are included in SPF Records
$IpsToCheck = @("40.107.67.0","104.47.612.0","52.100.146.0","40.107.0.0","104.47.0.0","52.100.0.0")
$domain = "spf.protection.outlook.com"
#A better approach would be to validate if the domain is user in a primary email address
$IpMissing = @()
foreach($IpToCheck in $IpsToCheck){
$DNS = Resolve-DnsName -Type TXT -Name $domain |where{$_.Strings -like "*v=spf1*"}
if($DNS.strings -like "*$($IpToCheck)*"){ $DNS.strings
}elseif($DNS.strings -like "*include:*"){
foreach($include in $($dns.Strings.split(" ")| where {$_ -like "include:*"})){
$tDns = Resolve-DnsName -Type TXT -Name $($include.split(":")[-1])
if($tDNS.strings -like "*$($IpToCheck)*"){$tDNS.strings }
}
}
$IpMissing += $IpToCheck
}
$IpMissing
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment