[root@ops-72 ~/testip]# ipcalc -h
-b, --broadcast Display calculated broadcast address(显示指定ip和子网掩码的广播地址)
-h, --hostname Show hostname determined via DNS(显示指定ip的主机名)
-m, --netmask Display default netmask for IP (class A, B, or C)(显示指定ip的子网掩码--特指默认,实际未必是)
-n, --network Display network address(显示指定ip的网络地址)
-p, --prefix Display network prefix(显示网络前缀)
-s, --silent Don't ever display error messages (不显示错误信息)
例:[root@ops-72 ~/testip]# ipcalc -pnbm 101.106.64.0/19
NETMASK=255.255.224.0 (-m选项)
PREFIX=19 (-p选项)
BROADCAST=101.106.95.255 (-b选项)
NETWORK=101.106.64.0 (-n选项)
以下是个小脚本所IP写到sip文件中,执行sh test.sh,然后在dip中查看
[root@ops-72 ~/testip]# cat sip
101.106.64.0/19
101.126.0.0/18
test.sh脚本内容为:
[root@ops-72 ~/testip]# cat test.sh
#!/bin/bash
iplist="./sip"
logname=`date '+%Y-%m-%d'`
echo "-----------------${logname}----------------" > ./dip
if [ ! -f sip ]; then
echo "sip sip file successfully created the file does not exist, please add sip IP data file by line!"
touch sip
exit 0
fi
for ip in `cat $iplist`
do
#tmp[0]="hostip"
#tmp[1]="data"
#tmp[2]="log"
tmp[0]=$host
tmp[1]=`ipcalc -pnbm ${ip}|grep NETWORK|awk -F= '{print $2}'`
tmp[2]=`ipcalc -pnbm ${ip}|grep BROADCAST|awk -F= '{print $2}'`
#tmp[3]=`ipcalc -pnbm ${ip}|grep NETWORK|awk -F= '{print $2}'`
echo "${tmp[1]} ${tmp[2]}" >>dip
done
echo "IP address of a successful conversion, check the dip file!"
查看dip文件:
[root@ops-72 ~/testip]# cat dip
-----------------2013-03-27----------------
101.106.64.0 101.106.95.255
101.126.0.0 101.126.63.255