I saw this and liked that it was a) in native bash, and b) runs in parallel so takes less than a second to scan the subnet. Run with: ./online-ip.sh 192.168.1
#!/bin/sh
# online-ip.sh
echo "Online IPs" > online-ip.txt
COUNTER=1
while [ $COUNTER -lt 255 ]
do
ping $1.$COUNTER -c 1 -w 400 | grep "icmp" >> online-ip.txt &
COUNTER=$(( $COUNTER + 1 ))
done
killall ping
cat online-ip.txt
Can we do something as fast and efficient as this in PowerShell, also in parallel? I know of ForEach-Object -Parallel
in PowerShell 6+ but my work servers are all locked to PS 5.1; surely 5.1 is good enough to do a bit of simple parallel operations? I know of things like nmap -sP
, but if bash can do this natively, surely PS 5.1 can too?
It would also be extremely useful to me if such a script could return the hostname and OS of the systems at the found IPs (I think that PowerShell has the edge over bash for more easily extracting information) if possible?