Shell脚本之IP网络地址和广播地址计算
#!/bin/bashIPPattern="(\\.){3}\"
maskPattern="||3"
while :
do
echo -e -n "Please input a legal IP address : "
read userInput
IPMask=`echo $userInput | egrep "$IPPattern/$maskPattern"`
#Such as 192.168.1.1/24
if [ -z "$IPMask" ] ;then
echo "Please input the right format. "
continue
fi
IPAddr=`echo $IPMask | cut -d/ -f1`
IPType=`echo $IPAddr | cut -d. -f1`
IPType=`echo $IPAddr | cut -d. -f2`
IPType=`echo $IPAddr | cut -d. -f3`
IPType=`echo $IPAddr | cut -d. -f4`
mask=`echo $IPMask | cut -d/ -f2`
echo "IP address is ${IPType}*${IPType}*${IPType}*${IPType} , Mask is $mask ."
((IPHex=IPType24 & 0x000000ff))
((IPHex=bcastAddr>>16 & 0x000000ff))
((IPHex=bcastAddr>>8 & 0x000000ff))
((IPHex=bcastAddr & 0x000000ff))
echo -e "Broadcast Address : ${IPHex}.${IPHex}.${IPHex}.${IPHex}"
done
页:
[1]