Home > powershell > Humble beginnings: DNS Resolving for a list of host names

Humble beginnings: DNS Resolving for a list of host names

Here’s my first small Powershell script to share. Tackling DNS cleanup and reorganization over multiple locations and DNS servers, one of my first tasks was to get a reference list of host names and IP Adresses for about twenty domains hosted by us. While ping or nslookup seemed still feasible to use, I anyhow decided to let a script do the tedious work. It takes just a few lines…

 # resolve-all.ps1
# (c) Marcus Schommler, 2011
# Reads in all lines of the specified file and tries DNS name resolution on every line.
# (Apparently the file should contain host names).
# The output is done with Write-Host in a 'XML-snippets' format for reuse
# in another script/project (testing DNS resolutions for multiple DNS servers and multiple host names).

$entries = Get-Content www-all-zones.txt
foreach ($e in $entries) {
   $ips = [System.Net.Dns]::GetHostAddresses($e)
   # A host can have multiple IP adresses, so we iterate over the result of GetHostAddresses():
   foreach ($ip in $ips) {
      # XML-snipped style output for reuse in another project (mass testing of DNS resolutions):
      Write-Host '<dns_test host="'$e'" ip="'$ip'"/>'
   }
}
Advertisements
Categories: powershell Tags: , , ,
  1. February 10, 2013 at 12:45

    I want to take note of this posting, “Humble beginnings: DNS Resolving for a list of host names meanderingmarcus” on my webpage.
    Do you care in case Ido it? Many thanks ,Herman

    • mschomm
      February 11, 2013 at 10:03

      Hi Herman, please go ahead and link to this blog post if you like!

  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: