文章详情

  • 游戏榜单
  • 软件榜单
关闭导航
热搜榜
热门下载
热门标签
php爱好者> php文档>计算网络广播地址的shell

计算网络广播地址的shell

时间:2005-09-04  来源:herotic

计算networkid netmask broadcast For Expamle: ./net.sh 192.168.1.0 255.255.252.0 Network number: 192.168.0.0 Broadcast address: 192.168.3.255 Netmask bits: 22

计算networkid netmask broadcast For Expamle: ./net.sh 192.168.1.0 255.255.252.0 Network number: 192.168.0.0 Broadcast address: 192.168.3.255 Netmask bits: 22 #!/bin/bash if [ $# -ne 2 ];then echo "Usage:./net.sh ipaddress netmask" exit fi ip=(${1//[![:digit:]]/ }) echo "$ip" mask=(${2//[![:digit:]]/ }) for i in ${mask[*]} do j=7 tag=1 while [ $j -ge 0 ] do k=$((2**$j)) if [ $(( $i & $k )) -eq $k ]; then if [ $tag -eq 1 ]; then (( n += 1 )) else echo -e " $2 is a bad netamsk with holes " exit fi else tag=0 fi (( j -= 1 )) done done for i in 0 1 2 3 do a=$a${a:+.}$((${ip[i]} & ${mask[i]})) b=$b${b:+.}$((${ip[i]} | (${mask[i]} ^ 255))) done echo Network number: $a echo Broadcast address: $b echo Netmask bits: $n

相关阅读 更多 +
排行榜 更多 +
辰域智控app

辰域智控app

系统工具 下载
网医联盟app

网医联盟app

运动健身 下载
汇丰汇选App

汇丰汇选App

金融理财 下载