[英]Shutting Down Windows Network Using Bash
Here's my current code, which works but is slow 这是我当前的代码,可以运行但是很慢
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
I would like to be able to go through these IPs and attempt to shut them down. 我希望能够通过这些IP并尝试将其关闭。 But if there is not a PC at that IP it has to wait for it to timeout before attempting the next one.
但是,如果该IP上没有PC,则必须等待PC超时再尝试下一个PC。 So how can I find and shutdown all windows PCs on a network?
那么,如何查找和关闭网络上的所有Windows PC? (they all have the same credentials)
(它们都具有相同的凭据)
A trivial solution is to just run a pile of them in parallel: 一个简单的解决方案是将它们并行运行:
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
This runs 255 at a time and waits for them all to finish. 一次运行255,并等待它们全部完成。 Smarter and more flexible parallelization can be had through
xargs
, sem
or parallel
if Windows supports that. 如果Windows支持,则可以通过
xargs
, sem
或parallel
进行更智能,更灵活的并行化。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.