CMD/Powershell – One Line Ping Sweep

Quick and dirty ping sweeps.

Command Prompt:

(for /L %a IN (1,1,254) DO ping /n 1 /w 3 192.168.0.%a) | find "Reply" > ping_only_replies.txt

Note: This one dumps to a file.

 

Powershell:

write-host "Ping Sweep!"; $FirstThreeOctets = Read-Host -Prompt 'First Three Octets (for example: 127.0.0)'; $FirstIP = Read-Host -Prompt 'Start IP (for example: 1)'; $LastIP = Read-Host -Prompt 'End IP (for example: 254)'; $FirstIP..$LastIP | foreach-object { (new-object System.Net.Networkinformation.Ping).Send($FirstThreeOctets + '.' + $_,150) } | where-object {$_.Status -eq 'success'} | select Address; Write-Host 'Done!'

Note: 150 is a timeout value to speed up the sweep.  Add ” | out-file -filepath ping_results.csv” to the end to dump to a file.

Another using parallel workflow:

workflow ParallelSweep { foreach -parallel -throttlelimit 4 ($i in 1..255) {ping -n 1 -w 100 10.0.0.$i}}; ParallelSweep | Select-String ttl

 

Leave a Reply

Your email address will not be published. Required fields are marked *