1、对某一段IP检查1-254
    #!/bin/bash
    . /etc/init.d/functions
    for var in {1..254};
    do
    ip=172.16.50.$var
    ping -c2 $ip >/dev/null 2>&1
    if [ $? = 0 ];then
    action “$ip” /bin/true
    else
    action “$ip” /bin/false
    fi
    done

    2、获取172.16.60.0/24网段可用ip的shell脚本
    #!/bin/bash
    ip=1
    while [ $ip != “254” ]; do
    ping 172.16.60.$ip -c 2 | grep -q “ttl=” && echo “172.16.60.$ip yes” || echo “172.16.60.$ip no”
    ip=expr "$ip" "+" "1"
    done

    3、获取172.16.50.0/24, 172.16.51.0/24, 172.16.60.0/24 三个网段的可用ip
    #!/bin/bash
    ip=1
    while [ $ip != “254” ]; do

    ping 172.16.50.$ip -c 2 | grep -q “ttl=” && echo “172.16.50.$ip yes” || echo “172.16.50.$ip no” >/dev/null 2>&1
    ip=expr "$ip" "+" "1"

    ping 172.16.51.$ip -c 2 | grep -q “ttl=” && echo “172.16.51.$ip yes” || echo “172.16.51.$ip no” >/dev/null 2>&1
    ip=expr "$ip" "+" "1"

    ping 172.16.60.$ip -c 2 | grep -q “ttl=” && echo “172.16.60.$ip yes” || echo “172.16.60.$ip no” >/dev/null 2>&1
    ip=expr "$ip" "+" "1"

    done