powershell,复制bash Parallel Ping

发布于 2025-01-25 04:10:35 字数 659 浏览 1 评论 0原文

我看到了这一点,喜欢它是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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文