1

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?

oguz ismail
  • 1
  • 16
  • 47
  • 69
YorSubs
  • 3,194
  • 7
  • 37
  • 60
  • 1
    Here's function [`Ping-Subnet`](https://github.com/proxb/AsyncFunctions/blob/master/Test-ConnectionAsync.ps1), which uses asynchronous task-based .NET APIs for parallel pinging. – mklement0 Apr 30 '22 at 13:29
  • These are incredible functions, thanks. I see his `Get-DNSHostEntryAsync` there is also very useful. Some of the techniques he uses there are fairly complex (to me), but it works great. Is there a way to quickly dotsource these functions directly from the RawContent? I tried `. (iwr https://raw.githubusercontent.com/proxb/AsyncFunctions/master/Test-ConnectionAsync.ps1 -UseBasicParsing).RawContent` but the console would not load the functions that way? – YorSubs Apr 30 '22 at 13:52
  • 2
    @YourSube, try `iex (irm https://raw.githubusercontent.com/proxb/AsyncFunctions/master/Test-ConnectionAsync.ps1)` - `. ` (dot-sourcing) only works with _files_. – mklement0 Apr 30 '22 at 14:20

0 Answers0