判断IP网段的shell脚本

 

#!/bin/bash
a=`ifconfig eth0 | grep 'inet addr' | awk -F: '{print $2}' | awk -F. '{print $1}'`
b=`ifconfig eth0 | grep 'inet addr' | awk -F: '{print $2}' | awk -F. '{print $2}'`
c=`ifconfig eth0 | grep 'inet addr' | awk -F: '{print $2}' | awk -F. '{print $3}'`
d=`ifconfig eth0 | grep 'inet addr' | awk -F: '{print $2}' | awk -F. '{print $4}' | awk '{print $1}'`
a1=`ifconfig eth0 | grep 'inet addr' | awk -F: '{print $4}' | awk -F. '{print $1}'`
b1=`ifconfig eth0 | grep 'inet addr' | awk -F: '{print $4}' | awk -F. '{print $2}'`
c1=`ifconfig eth0 | grep 'inet addr' | awk -F: '{print $4}' | awk -F. '{print $3}'`
d1=`ifconfig eth0 | grep 'inet addr' | awk -F: '{print $4}' | awk -F. '{print $4}'`
if [ $a1 = 255 ]
then
a2=$a
else
a2=0
fi
if [ $b1 = 255 ]
then
b2=$b
else
b2=0
fi
if [ $c1 = 255 ]
then
c2=$c
else
c2=0
fi
if [ $d1 = 255 ]
then
d2=$d
else
d2=0
fi
echo "$a2.$b2.$c2.$d2"

posted @ 2018-02-08 22:39  Leonardo-li  阅读(785)  评论(0编辑  收藏  举报