How can I write a Linux bash script that tells me which computers are ON in my LAN?

前端 未结 16 1540
攒了一身酷
攒了一身酷 2020-12-12 11:59

How can I write a Linux Bash script that tells me which computers are ON in my LAN?

It would help if I could give it a range of IP addresses as input.

16条回答
  •  野趣味
    野趣味 (楼主)
    2020-12-12 12:43

    #!/bin/bash
    
    for ((n=0 ; n < 30 ; n+=1))
    do
        ip=10.1.1.$n
        if ping -c 1 -w 1 $ip > /dev/null 2> /dev/null >> /etc/logping.txt; then  
            echo "${ip} is up" # output up
            # sintax >> /etc/logping.txt log with .txt format
        else
            echo "${ip} is down" # output down
        fi
    done
    

提交回复
热议问题