Chinaunix首页 | 论坛 | 博客
  • 博客访问: 57126
  • 博文数量: 17
  • 博客积分: 720
  • 博客等级: 军士长
  • 技术积分: 155
  • 用 户 组: 普通用户
  • 注册时间: 2006-03-21 13:34
文章分类

全部博文(17)

文章存档

2011年(1)

2009年(1)

2008年(5)

2007年(6)

2006年(4)

我的朋友
最近访客

分类:

2007-04-05 17:02:05

shell scripts说明:只支持C类及其子网。
 
#!/bin/bash
read -p "Please input an ipaddr of destination network:" ip
read -p "Please input destination network mask[255.255.255.0]:" mask
if [ -z $mask ];then
   mask=255.255.255.0
fi
ip1=${ip%%.*}
tempip1=${ip#*.}
ip2=${tempip1%%.*}
tempip2=${ip%.*}
ip3=${tempip2##*.}
ip4=${ip##*.}
mask1=${mask%%.*}
tempmask1=${mask#*.}
mask2=${tempmask1%%.*}
tempmask2=${mask%.*}
mask3=${tempmask2##*.}
mask4=${mask##*.}
destip1=$((ip1 & mask1))
destip2=$((ip2 & mask2))
destip3=$((ip3 & mask3))
destip4=$((ip4 & mask4))
destbcast=$((destip4 + 255 - mask4))
echo "the network address is: $destip4"
echo "the broadcast address is: $destbcast"
echo
let count=0
for (( i=destip4+1; $i-$destbcast; i++ ));
do
   ping -c2 $ip1.$ip2.$ip3.$i > /dev/null 2>&1
   if [ $? -ne 0 ];then
      echo "you can use:$ip1.$ip2.$ip3.$i"
      ((count++))
   fi
done
echo
echo "There are $count IPs can be used"
exit 0
阅读(1068) | 评论(2) | 转发(0) |
给主人留下些什么吧!~~