msgbartop
Everybody get your shell on!
msgbarbottom

Lookup reverse records of multiple IPs with Powershell

Here is a handy chunk of powershell code that uses the native windows command Nslookup to parse a list of IPs and output the IP and the reverse lookup value to a text file. This is especially usefull when you have a large number of IPs to check.

1
2
3
4
5
6
7
8
9
10
11
$ips = Get-Content nslookup.txt
$nslookupresults = "M:\Scripts\nslookupresults.txt"
clear-content $nslookupresults
 
Foreach ($ip in $ips)
{$output = nslookup $ip|out-null #A DNS server can be defined here
 
if ($output -match "name"){$ip | out-file $nslookupresults -append
($output -match "name")[0].remove(0,9) | out-file $nslookupresults -append
"" | out-file $nslookupresults -append}
}
  • Twitter
  • Facebook
  • LinkedIn
  • Digg
  • Google Bookmarks
  • Slashdot
  • StumbleUpon
  • Live
  • FriendFeed
  • Ping.fm
  • Print
  • email
  • PDF
  • RSS

Tags:

Reader's Comments

  1. |

    Thanks Shay. I’m relatively new to Powershell and a lot of the things Ive written are wrapped around native Windows shell commands and WMI. Slowly dipping into the .NET classes :-) .

    Reply to this comment
  2. |

    Instead of using legacy apps, why not let PoSh and .NET do the work (and in a one-liner):

    GC nslookup.txt | % {([System.Net.DNS]::GetHostByAddress($_)).AddressList} | Export-CSV “nslookup.csv” -NoTypeInformation -Force

    Reply to this comment

Leave a Comment