亚洲av成人无遮挡网站在线观看,少妇性bbb搡bbb爽爽爽,亚洲av日韩精品久久久久久,兔费看少妇性l交大片免费,无码少妇一区二区三区

  免費(fèi)注冊(cè) 查看新帖 |

Chinaunix

  平臺(tái) 論壇 博客 文庫(kù)
最近訪問板塊 發(fā)新帖
查看: 3222 | 回復(fù): 8
打印 上一主題 下一主題

劃分子網(wǎng)的 script -- CCNA 愛好者必看  關(guān)閉 [復(fù)制鏈接]

論壇徽章:
0
跳轉(zhuǎn)到指定樓層
1 [收藏(0)] [報(bào)告]
發(fā)表于 2004-10-15 11:36 |只看該作者 |倒序?yàn)g覽
此  script 可根據(jù)每個(gè)子網(wǎng)中 hosts 的個(gè)數(shù)及子網(wǎng)數(shù)目劃分子網(wǎng)。并列出
相應(yīng)的 prefix, netmask, total subnet number,  hosts per subnet.



  1. #!/bin/ksh
  2. #
  3. # This script produces subnet number and broadcast address
  4. # according to network number, subnet number and hosts number
  5. # per subnet.
  6. #

  7. set -A network ${1//(\D)/ }

  8. if [ $# -ne 3 ]; then
  9.         echo
  10.         echo Usage:  $0 netwok_number  subnet_number hosts_per_subnet
  11.         echo
  12.         echo For example:
  13.         echo
  14.         echo        "       $0 192.9.200.0  3 20"
  15.         echo
  16.         exit
  17. fi

  18. # Check the network number format

  19. if [ ${#network[*]} -ne 4 ]; then
  20.         echo Invalid network format
  21.         exit
  22. fi

  23. # Check the network class invalidation

  24. for (( i=0; i<=3; i++ )); do
  25.         if [ ${network[$i]} -gt 255 ]; then
  26.                 echo Invalid network class.
  27.                 exit
  28.         elif [ ${network[$i]} -ge 240 ]; then
  29.                 echo The network you input is a multicast address.
  30.                 exit
  31.         fi
  32. done

  33. # Check the network class

  34. if [ ${network[0]} -le 127 ]; then
  35.         bits=24
  36. elif [ ${network[0]} -ge 128 ]  && [ ${network[0]} -lt 192 ]; then
  37.         bits=16
  38. else
  39.         bits=8
  40. fi


  41. # Get the bits needed for subnets and hosts

  42. while true
  43. do
  44. if [ $((2**subnet)) -ge $2 ]; then
  45.         break
  46. else
  47.         (( subnet++ ))
  48. fi
  49. done
  50. while true
  51. do
  52. if [ $((2**host - 2)) -ge $3 ]; then
  53.         break       
  54. else
  55.         (( host++ ))
  56. fi
  57. done

  58. if [ $(( subnet + host )) -gt $bits ]; then
  59.         echo Too many subnets or hosts in your configuration
  60.         exit
  61. fi

  62. for (( i=31; i > (31 - host); i -- )); do
  63.         net[$i]=0
  64. done
  65. for (( i=0; i <= (31 - host); i ++ )); do
  66.         net[$i]=1
  67. done

  68. for (( l=0; l <= 7 ; l ++ )); do
  69.         (( a[0] += (2**(7 - l) * net[l])))       
  70.         (( a[1] += (2**(7 - l) * net[l + 8])))       
  71.         (( a[2] += (2**(7 - l) * net[l + 16])))       
  72.         (( a[3] += (2**(7 - l) * net[l + 24])))       
  73. done
  74. echo
  75. echo Network prefix: $(( 32 - host ))
  76. echo Network mask: ${a[0]}.${a[1]}.${a[2]}.${a[3]}
  77. echo Total subnets: $(( 2**(bits - host)))
  78. echo Hosts per subnet: $(( 2**host - 2))
  79. echo
  80. echo list $2 out of $(( 2**(bits - host))) subnets::
  81. echo

  82. for i in ${network[*]}
  83. do
  84.         j=7
  85.         while [ $j -ge 0 ]
  86.         do
  87.           k=$((2**$j))         
  88.           if [ $(( $i & $k )) -eq $k ]; then
  89.                 net[n]=1
  90.                 broadcast[n]=1
  91.           else
  92.                 net[n]=0
  93.                 broadcast[n]=0
  94.           fi
  95.           (( n ++ ))
  96.           (( j -- ))
  97.          done
  98. done
  99. for (( i=31; i > (31 - host); i -- )); do
  100.         net[$i]=0
  101.         broadcast[$i]=1
  102. done

  103. #for (( i=0; i < (2**subnet); i ++ )); do
  104. for (( i=0; i < $2; i ++ )); do
  105.         set -A a
  106.         for (( j=0; j < subnet; j ++ )); do
  107.           k=$((2**$j))         
  108.           if [ $(( $i & $k )) -eq $k ]; then
  109.                 net[$((32 - host - subnet + j))]=1
  110.                 broadcast[$((32 - host - subnet + j))]=1
  111.           else
  112.                 net[$((32 - host - subnet + j))]=0
  113.                 broadcast[$((32 - host - subnet + j))]=0
  114.           fi
  115.         done

  116.         for (( l=0; l <= 7 ; l ++ )); do
  117.                 (( a[0] += (2**(7 - l) * net[l])))       
  118.                 (( a[1] += (2**(7 - l) * net[l + 8])))       
  119.                 (( a[2] += (2**(7 - l) * net[l + 16])))       
  120.                 (( a[3] += (2**(7 - l) * net[l + 24])))       
  121.                 (( a[4] += (2**(7 - l) * broadcast[l])))       
  122.                 (( a[5] += (2**(7 - l) * broadcast[l + 8])))       
  123.                 (( a[6] += (2**(7 - l) * broadcast[l + 16])))       
  124.                 (( a[7] += (2**(7 - l) * broadcast[l + 24])))       
  125.         done
  126.         echo Network number: ${a[0]}.${a[1]}.${a[2]}.${a[3]} "      "  Broadcast address: ${a[4]}.${a[5]}.${a[6]}.${a[7]}
  127. done


復(fù)制代碼


運(yùn)行:



  1. $  ./1 192.9.200.0 4 30

  2. Network prefix: 27
  3. Network mask: 255.255.255.224
  4. Total subnets: 8
  5. Hosts per subnet: 30

  6. list 4 out of 8 subnets::

  7. Network number: 192.9.200.0        Broadcast address: 192.9.200.31
  8. Network number: 192.9.200.64        Broadcast address: 192.9.200.95
  9. Network number: 192.9.200.32        Broadcast address: 192.9.200.63
  10. Network number: 192.9.200.96        Broadcast address: 192.9.200.127
  11. $
  12. $  ./1 192.9.200.0 4 80
  13. Too many subnets or hosts in your configuration
  14. $
  15. $  ./1 168.153.0.0 4 80

  16. Network prefix: 25
  17. Network mask: 255.255.255.128
  18. Total subnets: 512
  19. Hosts per subnet: 126

  20. list 4 out of 512 subnets::

  21. Network number: 168.153.0.0        Broadcast address: 168.153.0.127
  22. Network number: 168.153.1.0        Broadcast address: 168.153.1.127
  23. Network number: 168.153.0.128        Broadcast address: 168.153.0.255
  24. Network number: 168.153.1.128        Broadcast address: 168.153.1.255
  25. $
  26. $  ./1 10.0.0.0 4 80

  27. Network prefix: 25
  28. Network mask: 255.255.255.128
  29. Total subnets: 131072
  30. Hosts per subnet: 126  

  31. list 4 out of 131072 subnets::

  32. Network number: 10.0.0.0        Broadcast address: 10.0.0.127
  33. Network number: 10.0.1.0        Broadcast address: 10.0.1.127
  34. Network number: 10.0.0.128        Broadcast address: 10.0.0.255
  35. Network number: 10.0.1.128        Broadcast address: 10.0.1.255

  36. $  ./1 250.0.0.0 4 80
  37. The network you input is a multicast address.
  38. $
  39. $  ./1 260.0.0.0 4 80
  40. Invalid network class.
  41. $
  42. $  d 200.0.0 4 80
  43. Invalid network format      
  44.       
復(fù)制代碼

論壇徽章:
1
榮譽(yù)會(huì)員
日期:2011-11-23 16:44:17
2 [報(bào)告]
發(fā)表于 2004-10-15 11:55 |只看該作者

劃分子網(wǎng)的 script -- CCNA 愛好者必看

強(qiáng)!

論壇徽章:
0
3 [報(bào)告]
發(fā)表于 2004-10-15 13:10 |只看該作者

劃分子網(wǎng)的 script -- CCNA 愛好者必看

so強(qiáng)!     

論壇徽章:
0
4 [報(bào)告]
發(fā)表于 2004-10-15 13:45 |只看該作者

劃分子網(wǎng)的 script -- CCNA 愛好者必看

怎么版主N久都沒露面了,這么強(qiáng)的貼要加精啊

論壇徽章:
0
5 [報(bào)告]
發(fā)表于 2004-10-16 01:17 |只看該作者

劃分子網(wǎng)的 script -- CCNA 愛好者必看

好貼勿沉~~~

論壇徽章:
1
榮譽(yù)會(huì)員
日期:2011-11-23 16:44:17
6 [報(bào)告]
發(fā)表于 2004-10-16 13:37 |只看該作者

劃分子網(wǎng)的 script -- CCNA 愛好者必看

幫樓上的兄弟----丁頁(yè)~~~

論壇徽章:
0
7 [報(bào)告]
發(fā)表于 2007-05-29 15:34 |只看該作者
為什么我的機(jī)器不支持set -A?
系統(tǒng)是RHEL 4 u4,bash3.0
$  echo  $KSH_VERSION
@(#)PD KSH v5.2.14 99/07/13.2

論壇徽章:
0
8 [報(bào)告]
發(fā)表于 2007-05-30 15:46 |只看該作者
誰(shuí)能解釋一下
set -A network ${1//(\D)/ } 是什么意思呢
還有$((2*subnet)) 是乘法運(yùn)算,$((2**subnet))是什么意思呢。

論壇徽章:
0
9 [報(bào)告]
發(fā)表于 2007-06-02 09:54 |只看該作者

set -A network ${1//(\D)/ } 什么意思

先頂下
在請(qǐng)教  set -A network ${1//(\D)/ }  什么意思,,

netwrok  匹配數(shù)字?
您需要登錄后才可以回帖 登錄 | 注冊(cè)

本版積分規(guī)則 發(fā)表回復(fù)

  

北京盛拓優(yōu)訊信息技術(shù)有限公司. 版權(quán)所有 京ICP備16024965號(hào)-6 北京市公安局海淀分局網(wǎng)監(jiān)中心備案編號(hào):11010802020122 niuxiaotong@pcpop.com 17352615567
未成年舉報(bào)專區(qū)
中國(guó)互聯(lián)網(wǎng)協(xié)會(huì)會(huì)員  聯(lián)系我們:huangweiwei@itpub.net
感謝所有關(guān)心和支持過ChinaUnix的朋友們 轉(zhuǎn)載本站內(nèi)容請(qǐng)注明原作者名及出處

清除 Cookies - ChinaUnix - Archiver - WAP - TOP