分享一个shell,用于检测局域网内可用的IP

#!/bin/bash
# ----------------------------------
# 脚本功能:用于获取局域网内可用的IP地址
# ---------------------------------- . /etc/init.d/functions IP1=`ifconfig | grep "broadcast" | awk '{print $2}' | awk -F. '{print $1}'` IP2=`ifconfig | grep "broadcast" | awk '{print $2}' | awk -F. '{print $2}'` IP3=`ifconfig | grep "broadcast" | awk '{print $2}' | awk -F. '{print $3}'` for i in {1..254}; do IPv4="$IP1.$IP2.$IP3."$i ping -c 2 $IPv4 > /dev/null 2>&1 if [ $? = 0 ];then action "$IPv4" /bin/true else action "$IPV4" /bin/false fi done

 

上一篇:获取OpenWrt mac地址


下一篇:学习一个 Linux 命令:pstree