-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdnsresolver.ps1
47 lines (44 loc) · 1.42 KB
/
dnsresolver.ps1
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
#function Get-FileName
Function Get-FileName($initialDirectory)
{
[System.Reflection.Assembly]::LoadWithPartialName("System.windows.forms") |
Out-Null
$OpenFileDialog = New-Object System.Windows.Forms.OpenFileDialog
$OpenFileDialog.initialDirectory = $initialDirectory
$OpenFileDialog.filter = "All files (*.*)| *.*"
$OpenFileDialog.ShowDialog() | Out-Null
$OpenFileDialog.filename
}
#end function Get-FileName
$path = Get-FileName
if (-Not($path)) { exit }
$hosts = Get-Content $path
$totalhosts = $hosts.length
echo "Looking up DNS records for $totalhosts hosts...please be patient..."
$textresults = @()
$hostcounter = 1
foreach ($indivhost in $hosts)
{
echo "Looking up host $hostcounter of $totalhosts"
$hostcounter += 1
Try
{
$hostentry = [System.Net.Dns]::GetHostEntry($indivhost)
$singletextresult = """$($hostentry.hostname)"""
foreach ($address in $hostentry.addresslist)
{
$singletextresult += ",""$($address.IPAddressToString)"""
}
$textresults += $singletextresult
}
catch
{
$singletextresult = """$indivhost"",""Not Found"""
$textresults += $singletextresult
}
}
$savefilename = "DNSLookup_Results.csv"
$textresults | Out-File $savefilename -Encoding utf8
echo "DNS Lookups completed. Results are stored in $savefilename"
Write-Host "Press any key to continue ..."
$x = $host.UI.RawUI.ReadKey("NoEcho,IncludeKeyDown")