使用 Bash 关闭 Windows 网络

Shutting Down Windows Network Using Bash

这是我当前的代码,可以运行但速度很慢

for i in {1..255..1}; do
  for j in {1..255..1}; do
    ip="10.8.$i.$j"
    sudo net rpc shutdown -I $ip -U Username%Password -t 1 -f
    echo $ip
  done
done

我希望能够通过这些 IP 并尝试将它们关闭。但是,如果该 IP 上没有 PC,它必须等待它超时,然后再尝试下一个。那么如何找到并关闭网络上的所有 windows 台 PC? (他们都有相同的凭据)

一个简单的解决方案是 运行 一堆并行的:

for i in {1..255..1}; do
  for j in {1..255..1}; do
    ip="10.8.$i.$j"
    sudo net rpc shutdown -I $ip -U Username%Password -t 1 -f &
    echo $ip
  done
  wait
done

这 运行 一次 255 并等待它们全部完成。如果 Windows 支持,可以通过 xargssemparallel 实现更智能、更灵活的并行化。