So firstly, I’ve just seen that’s its been over 3 months since I last posted – for anyone that looks back here regularly, Sorry! Thanks for coming back though, I am going to try to be more active.
I started a new job at the end of August as a Network Engineer as part of the network team in a data centre supporting multiple European sites. It’s been a steep learning curve and has eaten most of my time. I’ve learnt more in the last three months than I thought possible, and loved every minute of it!
I’ve got a lot of things I could post about, but today I thought I’d start with a handy little script which I wrote in Windows Powershell which can take a list of host names (or IP’s) from a text file, and perform a DNS Lookup on them.
In my job I quite often find myself with a whole bunch of host names that I need IP’s for. I found it quite repetitive to keep opening a command prompt and typing “nslookup hostname”, then copying and pasting it somewhere. So I started googling. I have never used Powershell before, so this was a good little project to learn a few things.
There’s a few good things to be found by googling for an introduction to powershell, so I won’t go over it here. The highlight is probably this article: Running Windows PowerShell Scripts which tells you how to actually run the scripts.
My scripts takes a text file as an input (which it opens a usual Windows “Open” dialog to let you choose), which needs to contain a list of hosts, one host per line. It will then perform a .NET DNS Lookup ([System.Net.Dns]::GetHostEntry), which is very similar to an nslookup but it returns an object which is more easily manipulated than the text based nslookup. It then outputs to a CSV file, with one line per entry containing all of the IP’s returned (in the case of multiple DNS entries).
The script is available here: Bulk DNS Lookup
Included in the file is the PowerShell script, which I will past in full on the next page. There is also a sample hostlist.txt file. And finally, a shortcut. The shortcut runs the script, bypassing the PowerShell execution policy settings. It is just a shortcut to: “C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe -executionpolicy bypass -Sta -File script_dns_lookup.ps1”
I hope this is useful for someone! :o)