Home » PowerShell » DNS Reverse Lookup (IP to HostName) Script with Auto Generate Excel File

DNS Reverse Lookup (IP to HostName) Script with Auto Generate Excel File


<br />###########################################################################<br />#<br /># NAME: DNS Reverse Lookup (IP to HostName) Script with Auto Generate Excel File<br />#<br /># AUTHOR: J.Malek (www.malekjakir.com) Email: malek dot one zero four zero at gmail dot com<br />#<br /># COMMENT: This PowerShell script can be used to check (IP to HostName) list of Servers/computers for Reverse (A) DNS records.<br /># Line#32 - Please Change the path of IPs.txt to your file location.<br /># Note: Please put the one IP Address per line.<br /># VERSION HISTORY:<br /># 1.0 2/20/2012 -<br />#<br />###########################################################################<br /><br />$ErrorActionPreference = "silentlycontinue"<br /><br />$a = New-Object -comobject Excel.Application<br />$a.visible = $True<br /><br />$b = $a.Workbooks.Add()<br />$c = $b.Worksheets.Item(1)<br /><br />$c.Cells.Item(1,1) = "IP Address"<br />$c.Cells.Item(1,2) = "Reverse DNS Record"<br /><br />$d = $c.UsedRange<br />$d.Interior.ColorIndex = 19<br />$d.Font.ColorIndex = 11<br />$d.Font.Bold = $True<br /><br />$intRow = 2<br /><br />$colComputers = get-content "C:\SCRIPTS\DNS_Lookup\ReverseLookup\IPs.txt"<br />foreach ($strComputer in $colComputers)<br />{<br />$RVSIP = [System.Net.Dns]::GetHostbyAddress($strComputer) | Add-Member -Name IP -Value $strComputer -MemberType NoteProperty -PassThru | Select IP, HostName<br /><br />$c.Cells.Item($intRow,1) = $RVSIP.IP<br />$c.Cells.Item($intRow,2) = $RVSIP.HostName<br /><br />$intRow = $intRow + 1<br />}<br />$d.EntireColumn.AutoFit()<br />cls<br />Write-Host "######## This Script is completed now ########"<br />
Advertisements

3 Comments

  1. na says:

    Nice script! However, if a hostname does not exist for the IP the scrip repeats the previous hostname. Is there a way to have it just print the IP or leave it blank?

  2. pcennui says:

    Excellent Script…thanks!

  3. Kim says:

    Malek,

    You can geolocate the city of IP address using Excel add-in now.

    http://www.ip2location.com/free/excel-addin

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: