Score:0

nslookup script for return empty hostnames

vn flag

I want to write script which returns hostnames with no IP. I wrote following part of the script but I don't know how can I return the empty answers. Thanks in advance

$numbers=1..255
foreach ($number in $numbers){
{
    nslookup host$number
}
br flag
is there a reason NOT to use the powershell cmdlet for this? look up `powershell nslookup` for info on that.
Score:1
ru flag

If you want to use nslookup from Powershell, you will have to process the returned result as it is just text. Instead, use Resolve-DnsName Powershell cmdLet.

Note that the command will return all DNS records, so the result can be an array of objects.

Here is a small example on how you can use it (I replaced your foreach loop with for):

for($i=1 ; $i -le 255 ; $i++) {

    $DnsQuery = $null
    [array]$DnsQuery = Resolve-DnsName -Name "host$i" -ErrorAction SilentlyContinue

    # If no DNS record found, process next host
    if($DnsQuery -eq $null) {
        Write-Host "No DNS record found for host$i"
        continue ;
    }

    # Look for DNS record without IP address
    foreach($Result in $DnsQuery) {
        if($Result.IPAddress -eq $null) {
            Write-Host "DNS record without IP address found for host$i (Record type: $($Result.Type))"
        }
    }

}
mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.