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

Ping-IPrange.ps1
 
 
 
 
 
4.5 Star
(11)
9,371 times
Add to favorites
Networking
8/30/2014
E-mail Twitter del.icio.us Digg Facebook
  • Not a question, but a snippet
    2 Posts | Last post April 24, 2014
    • PS > Start-SubnetQuery
      
      This will scan the IP Ranges that are specified in the script, query the active devices for the OS Version (using WMI), and spit the results to CSV Files that are named by the first IP of each range.
      
      Comes in handy to inventory how many XP Machines you still have left...
      
      function Get-OSVersion {
      	[CmdletBinding()]
      	param(
      		[Parameter(Position=0, Mandatory=$true)]
      		[System.String]
      		$IPAddress = ''
      	)
          $Win32_OS = Get-WmiObject Win32_OperatingSystem -computer $IPAddress
          return $Win32_OS.Caption
      }
      function Set-Subnets {
          $subnets = @()
          $subnets += ,@("192.168.99.1","192.168.99.255")
          $subnets += ,@("192.168.44.1","192.168.44.255")
          $subnets += ,@("192.168.95.1","192.168.95.255")
          $subnets += ,@("192.168.94.1","192.168.94.255")
          $subnets += ,@("192.168.92.1","192.168.92.255")
          return $subnets
      }
      function Start-SubnetQuery {
          $MyNetwork = Set-Subnets
          foreach ($subnet in $MyNetwork) {
              Write-Output "Pinging subnet: " $subnet[0]
              Query-Subnet -StartAddress $subnet[0] -EndAddress $subnet[1]
          }
      }
      
      
    • Thank you for sharing that code.
      I would like to suggest that you post this in the gallery so other users can find it.
  • please help, I couldn't get it working
    6 Posts | Last post April 24, 2014
    • I tried the following way, no luck...
      
      .\Ping-IPRange.ps1 -StartAddress 192.168.16.1 -EndAddress 192.168.16.254 -Interval 10
      
      although I tried with a valid IP address, it doesn't work, too.
      
      .\Ping-IPRange.ps1 -StartAddress 192.168.16.2 -EndAddress 192.168.16.2 -Interval 10
      
      
      am I missing anything?
    • Hi Ice-cream,
      
      The script just loads a function called Ping-IPRange.
      To use it open powershell or powershell-ice and run the script once and then call the function on the command line.
      
      for example:
      
      C:\Scripts\> .\Ping-IPRange.ps1
      
      C:\Scripts\> Ping-IPRange -Start 192.168.16.1 -End 192.168.16.254 -Int 10
      
      For more information on how to use or make functions go to https://blogs.technet.com/b/heyscriptingguy/archive/2013/04/09/using-powershell-functions-best-practices.aspx
      
      
      
      
    • My previous answer was to short, the easiest way to use the script is to open it in Powershell-ISE, run the script an then run the command.
      I will try modify the script to make it work with script arguments.
    • Thanks gaff, I got it working after reading your reply. I actually some interesting idea, but I am unsure if that will even work.
      
      It is quite usual to see an undocumented network environment. There are PING sweep & SNMP sweep can help for discovery work.
      
      If that happen to be a non unified environment, it can be quite painful to multiple SNMP sweep with different community strings, and consolidate the output.
      
      What I am thinking is to define a list of possible community string. After detecting an IP, do a SNMP query and confirm which string works, and output to an extra column  listing the working string.
      
      This can potentially expand to every make SNMP query on a known OID that will return the device name or description, becoming another column.
      
      I would love to hear your comment, Thanks
    • Doing a SNMP query would be a nice feature but it will take a lot of work.
      Many scripters took up the challenge but, as far as I can see, no one has managed to come up with a script that can do it without the help of an external piece of code.
      
      Nevertheless I will it a try to come up with a simple solution.
    • Thank you for sharing that code.
      I would like to suggest that you post this in the gallery so other users can find it.
11 - 12 of 12 Items