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

前端 未结 16 1425
攒了一身酷
攒了一身酷 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:55

    As other posters pointed out, nmap is the way to go, but here's how to do the equivalent of a ping scan in bash. I wouldn't use the broadcast ping, as a lot of systems are configured not to respond to broadcast ICMP nowadays.

    for i in $(seq 1 254); do
        host="192.168.100.$i"
        ping -c 1 -W 1 $host &> /dev/null
        echo -n "Host $host is "
        test $? -eq 0 && echo "up" || echo "down"
    done
    

提交回复
热议问题