Quantcast
Channel: PowerShell.com – PowerShell Scripts, Tips, Forums, and Resources
Viewing all articles
Browse latest Browse all 6937

Scan IP range and resolve DNS addresses

$
0
0

Here is what I have so far;

1..255 | foreach-object { (new-object System.Net.Networkinformation.Ping).Send("10.0.0.$_") } | where-object {$_.Status -eq "success"} | select address

This returnes a list of IP addresses. What I want to do is resolve them to DNS names.

 

This command resolves $address to DNS name 

"10.0.0.5"=$address

[System.Net.Dns]::GetHostbyAddress("$address")

 

My script looks like this but does not work;

1..255 | foreach-object { (new-object System.Net.Networkinformation.Ping).Send("10.1.1.$_") } | where-object {$_.Status -eq "success"} | select address=$address | foreach-object { (new-object System.Net.Dns.GetHostbyAddress("$address")) }

 

I get this error;

new-object : Cannot find type [System.Net.Dns.GetHostbyAddress]: verify that the assembly containing this type is

loaded.

 

I have tried many different formats for loading the System.Net.Dns.GetHostbyAddress bit..

 

like 

foreach-object { (new-object System.Net.Dns.GetHostbyAddress("$address")) }

foreach-object { (new-object [System.Net.Dns]::GetHostbyAddress("$address")) }

foreach-object { (new-object '[System.Net.Dns]::GetHostbyAddress'("$address")) }

 

and quite a few more

 

Please help


Viewing all articles
Browse latest Browse all 6937

Trending Articles