Assignment 3.1 Powershell and DNS - zacharylongo/Tech-Journals GitHub Wiki
Goal: Create a script that resolves DNS names and takes a network prefix and DNS server to use.
Script:
# Define the network prefix and DNS server
$NetworkPrefix = "192.168.3"
$DnsServer = "192.168.4.4"
# Define the range of IP addresses to resolve
$StartIpAddress = 1
$EndIpAddress = 254 # Adjust this as needed for your subnet size
# Iterate through the IP addresses in the range
for ($i = $StartIpAddress; $i -le $EndIpAddress; $i++) {
$IpAddressToResolve = "$NetworkPrefix.$i"
# Resolve the IP address using the specified DNS server
$result = Resolve-DnsName -Name $IpAddressToResolve -Server $DnsServer -ErrorAction Ignore
# Output the result (IP address and DNS name)
if ($result) {
Write-Host "Resolved $IpAddressToResolve to $($result.NameHost)"
} else {
Write-Host "Failed to resolve $IpAddressToResolve"
}
}