powershell,复制bash Parallel Ping
我看到了这一点,喜欢它是a)在本地狂欢中,b)并行运行,因此不到一秒钟的时间来扫描子网。运行:/inline-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
我们可以在PowerShell中做得像PowerShell一样快速有效吗?我知道powershell 6+中的foreach -object -parallel ,但我的工作服务器都锁定为PS 5.1;肯定是5.1足够好,可以做一些简单的并行操作吗?我知道
nmap -sp
之类的事情,但是如果Bash可以在本地进行此操作,那么PS 5.1也可以吗?
如果这样的脚本可以返回发现IPS的系统的主机名和操作系统(我认为PowerShell在可能的情况下具有更轻松地提取信息的优势),这也对我来说非常有用。 ?
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论