简体   繁体   中英

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. But if there is not a PC at that IP it has to wait for it to timeout before attempting the next one. So how can I find and shutdown all windows PCs on a network? (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. Smarter and more flexible parallelization can be had through xargs , sem or parallel if Windows supports that.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM