批量ping探测网段ip

2022-09-19 10:50:43 浏览数 (2)

判断 192.168.0.0/24 网络里,当前在线的 IP 有哪些,能 ping 通则认为在线

# 脚本如下

代码语言:javascript复制
#!/bin/bash

for ip in `seq 1 255`;do
    ping -c 1 192.168.0.$ip > /dev/null 2>&1
    if [ $? -eq 0 ];then
        echo "192.168.0.$ip UP"
    else
        echo "192.168.0.$ip DOWN"
    fi
done

# 执行效果

代码语言:javascript复制
[root@summer include]# ./ping.sh 
192.168.0.1 UP
192.168.0.2 DOWN
192.168.0.3 DOWN
192.168.0.4 DOWN
192.168.0.5 DOWN
192.168.0.6 DOWN
192.168.0.7 UP
192.168.0.8 UP
192.168.0.9 UP
192.168.0.10 UP
192.168.0.11 UP
192.168.0.12 DOWN
192.168.0.13 UP
192.168.0.14 UP
192.168.0.15 DOWN
192.168.0.16 UP
192.168.0.17 UP
192.168.0.18 UP
192.168.0.19 UP
192.168.0.20 UP
192.168.0.21 DOWN
192.168.0.22 DOWN
192.168.0.23 DOWN
192.168.0.24 DOWN
192.168.0.25 DOWN
192.168.0.26 DOWN
...

0 人点赞