wolong 发表于 2018-8-22 13:20:23

shell子网计算器

  #!/bin/bash
  if [ $UID -ne 0 ];then
  echo "Your are not the root ....";exit 1
  fi
  if [ $# -ne 2 ];then
  echo "Usage: $0 10.1.1.1 255.255.255.0";exit -1
  fi
  Judge()
  {
  num=`echo $1| grep -o '\.'|wc -l`
  [ "$num" -ne 3]&&(echo " Error : It is not userful....")
  }
  Turn10to2()
  {
  OB=`echo "obase=2;ibase=10;$1"|bc`
  echo $OB
  }
  Turn2to10()
  {
  OB=`echo "obase=10;ibase=2;$1"|bc`
  echo $OB
  }
  rmfile()
  {
  rm -fr /mnt/ipaddress.log
  rm -fr /mnt/netmask.log
  rm -fr /mnt/_1.log
  rm -fr /mnt/ip_mask.log
  }
  WANZHENG()
  {
  unset tmp;tmp=$1
  _11=`echo $tmp |wc -c`
  if [ $_11 -lt 9 ];then
  _22=`expr 9 - $_11`
  _00=`for ((t=1;t/mnt/ipaddress.log
  done
  IP=`cat /mnt/ipaddress.log| tr -d'\n' |sed 's/\./\n/4g'`
  fi
  echo "Judging the netmask....."
  Judge $2
  unset netmask;netmask=$2
  echo $netmask |awk 'split($0,array,"."){for (i=1;i
页: [1]
查看完整版本: shell子网计算器