Windows Ping Sweep for live hosts

  • Post author:
  • Post category:Windows

I used this one day to see how many IP’s I was using in the network by doing a ping sweep.

for /l %i in (1,1,254) do @ping 192.168.1.%i -n 1 -w 100 | find “Reply”

This will ping all addresses from 192.168.1.1 to 192.168.1.254 one time each, wait 100ms for a reply.

for /l %i in (1,1,254) do @ping 192.168.1.%i -n 1 -w 100 | find “timed out”

This would let you know what is not in use if you were looking for a free IP address.

If you want to pipe it to a text file use >> filename.txt at the end of the command.

 

Now if you want to see if the IP has a DNS record for example if the host got a DHCP address most cases it would of sent it’s hostname, use the following command with IP address

ping -a 192.168.1.1

 

For Power Shell you can run the following

 

1..254 | ForEach-Object {
$ip = “192.168.1.$_”
$result = Test-Connection -ComputerName $ip -Count 1 -Quiet
if ($result) {
Write-Host “Reply from $ip”
}
}