Fast Ping Sweep Asynchronous

 I have seen most of the Powershell IP scanner, ping sweeping scripts but none of them uses the PingASync method.The "problem" with synchronous scripts is that they have to wait until a node replies or times out before continuing to the next address.Using this approach may take s

4.5 Star
9,904 times
Add to favorites
E-mail Twitter Digg Facebook
  • how loop only ip address range?
    2 Posts | Last post October 27, 2019
    • Hey,
      great Job!
    • Thank you,
       I hope it save you some time
  • export
    1 Posts | Last post November 10, 2017
    • Hey,
      great Job!
      Is it possible to Export only the hostnames?
      Tried with:
      $MySubnet = Ping-IPRange -StartAddress -EndAddress -Interval 20
      $addis = $MySubnet | ft Ipaddress,@{LABEL="FQDN"; EXPRESSION={[System.Net.Dns]::GetHostByAddress($_.IPaddress).Hostname}}
      add-content C:\bat\out.csv $addis 
      any idea?
  • ComputerName in the output
    1 Posts | Last post October 25, 2017
      is it possible to show the resolved ComputerName with this script? Or is it possible to extend this script for it?
      Thx in advance
  • Will this work across multiple subnets?
    2 Posts | Last post May 19, 2017
    • Can I use this to scan outside the subnet of the network I'm on? I am trying to batch rename all computers on my network in order to create a standard and I would like to be able to run this script only once.
    • Hi CJL84,
      You can scan any ip address as long as it will reply ICMP request. You could scan the entire internet!
  • Can we do this with Multiple Computers?
    2 Posts | Last post December 11, 2016
    • Could you please assist here to do the same quick ping check for Multiple computers in the network.
      This is very fast and wonderful script to fetch the status quickly. 
    • Hi Amol,
      I hear you, I could modify the script to handle an array of predefined IP addresses.
      On the other hand, why do you want to modify this script? There are many script out there that are already capable of doing this.
      For Example you could do something like this:
      [string[]]$iptargets = "","","" 
      [ScriptBlock]$test_connection = {Test-Connection $args -Count 1}
      $jobs =  foreach($iparg in $iptargets){Start-Job -ScriptBlock $test_connection -ArgumentList $iparg}
      Receive-Job -Id $ -Wait  -AutoRemoveJob
  • using a btach file
    1 Posts | Last post June 05, 2015
    • I want to run this script from a batch file and export it to a simple txt file.
      Can someone tell me the best way.
      Many thanks
  • What about unsuccessful request
    2 Posts | Last post May 15, 2015
    • I love you script, this is really elegant and definitely fast. 
      One thing I'm missing is the unsuccessful requests, to get them I've modified the condition If($_.SourceEventArgs.Reply.Status -eq "Success") by If($_.SourceEventArgs.Reply.Status), unfortunately using the regular or Rawoutput, when a request is unsucceful the IP address is 'lost' and return '0.0.0.' this
       Success             3 System.Net.NetworkInformation.PingOptions {97, 98, 99, 100...}
       Success             3 System.Net.NetworkInformation.PingOptions {97, 98, 99, 100...}
      TimedOut                0                                           {}
      TimedOut                0                                           {}
      TimedOut                0                                           {}
      TimedOut                0                                           {}
      Any idea how to get the IP back for unsuccessful request ? The IP is show in the Write-Progess so there has to be a way.
    • Hi Cyreli,
      Glad you like my scrip. Luckily i used the reversed address in the name so i could resolve any event in case some thing went wrong.
      Now I can use it to get the IP addres back to the event.
      You can simply replace the $Reply statement in the end of the script.
              $Reply = Get-Event -SourceIdentifier "ID-Ping*" | ForEach { 
                      $_.SourceEventArgs | select @{
                            Name="IPAddress"   ; Expression={([System.Net.IPAddress]($_.UserState.trimstart('Ping_'))).GetAddressBytes()[3..0] -join '.'}},
                          @{Name="Bytes"       ; Expression={$_.Reply.Buffer.Length}},
                          @{Name="Ttl"         ; Expression={$_.Reply.Options.Ttl}},
                          @{Name="ResponseTime"; Expression={$_.Reply.RoundtripTime}},
                          @{Name="Status"      ; Expression={$_.Reply.Status}}
      Have Fun!
  • Truncated output in multiple runs
    2 Posts | Last post November 21, 2014
    • I added this to a script of mine that pulls subnets and presents a menu.  You select which subnet and it does it's job, shows results, and re-displays the menu.  The issue I have is the Header Names are only shown for the first job.  Output is correct every time I run it (IP's and reply results) but It will never show the Header again.  Any idea's
    • Hi Koo Amon,
      I'm glad you like the script and I would like to help you but I can not see what you see.
      Could you post your script here or on the TechNet forum?
  • Cannot convert value "3232235774" to type "System.Int32". Error:
    3 Posts | Last post August 30, 2014
    • I too am getting this error when I try to run the script on windows 2008  
      PS D:\Repository\Scripts\Powershell\Staging> $PSVersionTable.psversion
      Major  Minor  Build  Revision
      -----  -----  -----  --------
      2      0      -1     -1
      If it matters...
    • Hi, 
      I have tried to reproduce this error many times but I have never seen it.
      Could you please give me the whole error output?
      By typing  $Error[0]|Format-List * -force you get all the data about the last error.
    • Hi idfkoctgam,
      I have tested the script on a Server 2008 32bit with a clean install and the same PowerShell version. 
      I still wasn't able to reproduce the error but I have also tested a newer version of the function.
      Could you please download the new script and test it on your environment?
      I really appreciate any help getting this bug.
  • Getting error
    2 Posts | Last post June 24, 2014
    • Hi
      I'm getting this error, when running the script:
      Cannot convert value "3232235774" to type "System.Int32". Error: "Værdien var enten for stor eller for lille til en Int32."
      I've typed in as start and as end. The error states, that the value is either too big or too small for an Int32.
      Question: How do I output the result, fx to an CSV file and can I get the hostnames too for the pinged IP addresses?
    • Hi Frank, That's odd.. 
      The error is correct on the fact that 3232235774 is to big for an Int32, that is why I use an unsigned 32 bit variable, [UInt32].
      There a four variable in my function that use an Uint32: $StartAddrInt, $EndAddrInt, $DeltaInt and $x.
      The function will load in the global scope but the variable in the function are not. 
      If you where to create a variable with the same name as one of the variable in the function PowerShell will not autosense the type it needs to be and it could generate such an error as yours.
      For the CSV output with hostname you could use the following line:
      Ping-IPRange -StartAddress -EndAddress | select IPAddress,Bytes,Ttl,ResponseTime,@{LABEL="HostName"; EXPRESSION={[System.Net.Dns]::GetHostByAddress($_.IPaddress).Hostname}} | Export-Csv .\pingoutput.csv -NoTypeInformation
1 - 10 of 12 Items