Add dns lookups to this script

This topic contains 1 reply, has 2 voices, and was last updated by Profile photo of Øyvind Kallstad Øyvind Kallstad 1 year, 12 months ago.

  • Author
    Posts
  • #20974
    Profile photo of Robert
    Robert
    Participant

    Hello powershell.org 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()
    [Array]::Reverse($ip1)
    $ip1 = ([System.Net.IPAddress]($ip1 -join '.')).Address

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

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

  • #20975
    Profile photo of Øyvind Kallstad
    Øyvind Kallstad
    Participant

    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 http://msdn.microsoft.com/en-us/library/system.net.dns_methods(v=vs.110).aspx

You must be logged in to reply to this topic.