Add dns lookups to this script

This topic contains 1 reply, has 2 voices, and was last updated by  Øyvind Kallstad 3 years, 3 months ago.

  • Author
  • #20974


    Hello I'm very new to powershell and was given this script, I'll post credit here after he says it's okay if I share who he is.

    I'd like to see if it's possible to add DNS lookups to resolve hostnames in this.

    #Ping Sweep
    function New-IPRange ($start, $end) {
    $ip1 = ([System.Net.IPAddress]$start).GetAddressBytes()
    $ip1 = ([System.Net.IPAddress]($ip1 -join '.')).Address

    $ip2 = ([System.Net.IPAddress]$end).GetAddressBytes()
    $ip2 = ([System.Net.IPAddress]($ip2 -join '.')).Address

    for ($x=$ip1; $x -le $ip2; $x++) {
    $ip = ([System.Net.IPAddress]$x).GetAddressBytes()
    $ip -join '.'
    $ping = New-Object System.Net.NetworkInformation.Ping
    New-IPRange | ForEach-Object {$ping.Send($_, 100)} | where {$_.status -eq "Success"}

  • #20975

    Øyvind Kallstad

    Yes, that is possible. The System.Net.Dns class have a method called GetHostEntry that you can use. You can read more about System.Net.Dns at

You must be logged in to reply to this topic.