Is there a command line based way to send pings to each computer in a subnet? Like
for(int i = 1; i < 254; i++)
ping(192.168.1.i);
t
This is a modification of @david-rodríguez-dribeas answer above, which runs all the pings in parallel (much faster) and only shows the output for ip addresses which return the ping.
export COUNTER=1
while [ $COUNTER -lt 255 ]
do
ping $1$COUNTER -c 1 -w 400 | grep -B 1 "Lost = 0" &
COUNTER=$(( $COUNTER + 1 ))
done
In Bash shell:
#!/bin/sh
COUNTER=1
while [ $COUNTER -lt 254 ]
do
ping 192.168.1.$COUNTER -c 1
COUNTER=$(( $COUNTER + 1 ))
done
Under linux, I think ping -b 192.168.1.255 will work (192.168.1.255 is the broadcast address for 192.168.1.*) however IIRC that doesn't work under windows.
#!/bin/sh
COUNTER=$1
while [ $COUNTER -lt 254 ]
do
echo $COUNTER
ping -c 1 192.168.1.$COUNTER | grep 'ms'
COUNTER=$(( $COUNTER + 1 ))
done
#specify start number like this: ./ping.sh 1
#then run another few instances to cover more ground
#aka one at 1, another at 100, another at 200
#this just finds addresses quicker. will only print ttl info when an address resolves
I came late but here is a little script I made for this purpose that I run in Windows PowerShell. You should be able to copy and paste it into the ISE. This will then run the arp command and save the results into a .txt file and open it in notepad.
# Declare Variables
$MyIpAddress
$MyIpAddressLast
# Declare Variable And Get User Inputs
$IpFirstThree=Read-Host 'What is the first three octects of you IP addresses please include the last period?'
$IpStart=Read-Host 'Which IP Address do you want to start with? Include NO periods.'
$IpEnd=Read-Host 'Which IP Address do you want to end with? Include NO periods.'
$SaveMyFilePath=Read-Host 'Enter the file path and name you want for the text file results.'
$PingTries=Read-Host 'Enter the number of times you want to try pinging each address.'
#Run from start ip and ping
#Run the arp -a and output the results to a text file
#Then launch notepad and open the results file
Foreach($MyIpAddressLast in $IpStart..$IpEnd)
{$MyIpAddress=$IpFirstThree+$MyIpAddressLast
Test-Connection -computername $MyIpAddress -Count $PingTries}
arp -a | Out-File $SaveMyFilePath
notepad.exe $SaveMyFilePath
for i in $(seq 1 254); do ping -c1 192.168.11.$i; done