Last active
August 3, 2020 08:39
-
-
Save Jonatantwn/4653cabfe8320cc461fe137c29591898 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$FileList = (Get-ChildItem 'C:\Users\Dern\Desktop\DNSSCAN\Batchtest').fullname | |
$c1 = 0 | |
$lineamount = | |
$m = Get-Content -Path $FileList | Measure-Object -line | |
@($m).lines | |
$myOutput = @() # Declare empty array | |
foreach ($FileName in $FileList) { | |
$myOutput += foreach ($DomainName in (Get-Content $FileName)) { | |
try { | |
$NSRecords = Resolve-DnsName -Name $DomainName -Type NS -DnsOnly -EA 1 | Where-Object { $_.QueryType -eq 'NS' } | |
$DomainFinal = (Invoke-WebRequest -Uri $DomainName -UseBasicParsing -ErrorAction Continue).BaseResponse.ResponseUri.AbsoluteUri -replace "https://" -replace "http://" -replace "www." -replace ".dk/", ".dk" -replace ".com/", ".com" | |
[PSCustomObject]@{ | |
Resolved = $true | |
Rmatch = $DomainName -in $Domainfinal | |
DomainName = $DomainName | |
Domainfinal = $DomainFinal | |
NameServer = $NSRecords.NameHost | select -first 1 | |
'A-Record' = (Resolve-DnsName $DomainName -Type A).IPAddress | select -first 1 | |
'MX-Record' = (Resolve-DnsName $DomainName -Type MX).NameExchange | select -first 1 | |
Origin = $FileName | |
Status = $_.Exception.Message | |
} | |
$c1++ | |
Write-Host "Processing $DomainName" | |
Write-Progress -Id 0 -Activity 'Checking servers' -Status "Processing $($c1) of $(@($m).lines)" -CurrentOperation $DomainName -PercentComplete (($c1 / @($m).lines) * 100) | |
} catch { | |
[PSCustomObject]@{ | |
Origin = $FileName | |
Rmatch = $Rmatch | |
DomainName = $DomainName | |
Resolved = $false | |
NameServer = '?' | |
Domainfinal = '?' | |
'A-Record' = '?' | |
'MX-Record' = '?' | |
Status = $_.Exception.Message | |
} | |
} | |
} | |
} | |
$myOutput | Select-Object -Property DomainName, | |
@{n='Domainfinal'; e={$_.'Domainfinal' -join ', '}}, | |
@{n='Rmatch'; e={$_.'Rmatch' -join ', '}}, | |
Resolved, | |
@{n='NameServer';e={$_.NameServer -join ', '}}, | |
@{n='A-Record'; e={$_.'A-Record' -join ', '}}, | |
@{n='MX-Record'; e={$_.'MX-Record' -join ', '}}, | |
Status, | |
Origin | | |
Export-Csv -NoTypeInformation -Path C:\Users\Dern\Desktop\DNSSCAN\Output\output.csv | |
# or | |
$myOutput | Out-GridView |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
So am i!
Thanks for assisting :-)