-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDomainLookup.ps1
More file actions
93 lines (85 loc) · 3.67 KB
/
DomainLookup.ps1
File metadata and controls
93 lines (85 loc) · 3.67 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
#Lookup every possible TLD of a domain
$DomainRoot = @('twitter','google','facebook','microsoft')
$DNSServer = @('8.8.8.8')
[System.IO.DirectoryInfo]$OutputFolder = 'C:\Output'
#Premade variables
$DNSTypes = @('A_AAAA','NS','CNAME','SOA','MX','TXT','DS','RRSIG','NSEC','DNSKEY')
$TLDSource = "https://data.iana.org/TLD/tlds-alpha-by-domain.txt"
$AllTLD = (Invoke-WebRequest -UseBasicParsing -Uri $TLDSource).content -split "\n"
#Text document has a header so index starts at 1 and there are extra spaces at the end thus the '- 2'
$AllTLD = ($AllTLD[1..($AllTLD.Count - 2)]).ToUpper()
#---------------
Clear-Host
Write-Host '
=================
Domain TLD Lookup
================='
#Test for parent path
if ($OutputFolder.Exists -eq $false) {
Write-Host -ForegroundColor Red 'Output folder does not exist
'
exit 1
}
#DNSLookup
#Green if found, yellow if no ip, collision, or not yet official, and red if nothing found
foreach ($Domain in $DomainRoot) {
[System.IO.DirectoryInfo]$DomainFolder = $OutputFolder.FullName + '\' + $Domain
if ($DomainFolder.Exists -eq $false) {
New-Item -Path $OutputFolder -Name $Domain.ToUpper() -ItemType Directory | Out-Null
}
$Resolved = @()
$ResolvedNOIP = @()
$Collision = @()
$Unresolved = @()
Write-Host ''
Write-Host 'Running lookups for: ' -NoNewline && Write-Host -ForegroundColor Cyan $Domain.ToUpper()
Write-Host ''
foreach ($TLD in $AllTLD) {
$FullDomain = ($Domain + "." + $TLD)
$Lookup = foreach ($Type in $DNSTypes) {
$Result = Resolve-DnsName $FullDomain -Server $DNSServer -DnsOnly -Type $Type -ErrorAction SilentlyContinue
if (($Type -ne "SOA" ) -and ($Result.Type -eq "SOA")) {$Result = $null}
if (($null -ne $Result) -and ($Result.count -gt 0)) {$Result | Export-Csv -Path "$DomainFolder\$Type.csv" -Append -NoClobber -NoTypeInformation -Force}
$Result
}
$Lookup = $Lookup | Select-Object -Unique
Write-Host "Looked up " -NoNewline
if (($Lookup.IPAddress.count -gt 0) -or ($Lookup.IP4Address -gt 0) -or ($Lookup.IP6Address -gt 0)) {
if (($Lookup.IPAddress -eq "127.0.53.53") -or ($Lookup.IP4Address -eq "127.0.53.53")) {
Write-Host -ForegroundColor Yellow "$($FullDomain.ToUpper()) - Collision/Unofficial"
$Collision = $Collision + $FullDomain
$FullDomain | Out-File -FilePath "$DomainFolder\!Collision.txt" -Force -Append
} else {
Write-Host -ForegroundColor Green "$($FullDomain.ToUpper())"
$Resolved = $Resolved + $FullDomain
$FullDomain | Out-File -FilePath "$DomainFolder\!Resolved.txt" -Force -Append
}
} else {
if ($Lookup.count -gt 0) {
Write-Host -ForegroundColor Yellow "$($FullDomain.ToUpper()) - No IP"
$ResolvedNOIP = $ResolvedNOIP + $FullDomain
$FullDomain | Out-File -FilePath "$DomainFolder\!ResolvedNOIP.txt" -Force -Append
} else {
Write-Host -ForegroundColor Red "$($FullDomain.ToUpper())"
$Unresolved = $Unresolved + $FullDomain
$FullDomain | Out-File -FilePath "$DomainFolder\!Unresolved.txt" -Force -Append
}
}
}
}
#Report
Write-Host ("Resolved Domains (" + ($Resolved.count) + "):")
Write-Host ""
$Resolved
Write-Host ""
Write-Host ("Resolved Domains NOIP (" + ($ResolvedNOIP.count) + "):")
Write-Host ""
$ResolvedNOIP
Write-Host ""
Write-Host ("Collision/Unofficial Domains (" + ($Collision.count) + "):")
Write-Host ""
$Collision
Write-Host ""
Write-Host ("Unresolved Domains (" + ($Unresolved.count) + "):")
Write-Host ""
$Unresolved