天天看点

【shell脚本】监测局域网IP是否在线

一、脚本功能

    判断IP是否占用,通过ping命令检测的方法,ping通则认为被占用,并且将结果分别输出到IP_yes.txt和IP_no.txt。

二、脚本编写

#!/bin/bash

#Check the network is online

ip_num=192.168.1.

for i in `seq 1 254`

do

ping -c 2 $ip_num$i >/dev/null

        if [ $? -eq 0 ];then

                echo "echo $ip_num$i is yes"

                echo $ip_num$i is yes >> ip_yes.txt

        else

                echo "echo $ip_num$i is no"

                echo echo $ip_num$i is no >> ip_no.txt

        fi

done

本文转自 HMLinux 51CTO博客,原文链接:http://blog.51cto.com/7424593/1729128