network-utility 1.1.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (179) hide show
  1. checksums.yaml +7 -0
  2. data/README.md +2 -0
  3. data/document/acl-M6000-16E.md +27 -0
  4. data/document/acl-M6000-18S.md +27 -0
  5. data/document/acl-M6000-8.md +27 -0
  6. data/document/acl-M6000-8E.md +27 -0
  7. data/document/acl-MA5200G-8.md +204 -0
  8. data/document/acl-ME60-16.md +177 -0
  9. data/document/acl-ME60-X16.md +177 -0
  10. data/document/acl-NE40E-X16.md +204 -0
  11. data/document/acl-NE40E-X16A.md +204 -0
  12. data/document/acl-NE40E-X8.md +204 -0
  13. data/document/acl-NE40E.md +204 -0
  14. data/document/acl-NE5000E-20.md +25 -0
  15. data/document/acl-NE5000E-X16.md +25 -0
  16. data/document/acl-NE5000E-X16A.md +25 -0
  17. data/document/acl-NE80E.md +204 -0
  18. data/document/bgp-CR16010H-F.md +25 -0
  19. data/document/bgp-CR16018-F.md +25 -0
  20. data/document/bgp-CR19000-20.md +25 -0
  21. data/document/bgp-M6000-16E.md +25 -0
  22. data/document/bgp-M6000-18S.md +25 -0
  23. data/document/bgp-M6000-8.md +25 -0
  24. data/document/bgp-M6000-8E.md +25 -0
  25. data/document/bgp-MA5200G-8.md +25 -0
  26. data/document/bgp-ME60-16.md +25 -0
  27. data/document/bgp-ME60-X16.md +25 -0
  28. data/document/bgp-NE40E-X16.md +25 -0
  29. data/document/bgp-NE40E-X16A.md +25 -0
  30. data/document/bgp-NE40E-X8.md +25 -0
  31. data/document/bgp-NE40E.md +25 -0
  32. data/document/bgp-NE5000E-20.md +25 -0
  33. data/document/bgp-NE5000E-X16.md +25 -0
  34. data/document/bgp-NE5000E-X16A.md +25 -0
  35. data/document/bgp-NE80E.md +25 -0
  36. data/document/config.md +1153 -0
  37. data/document/document.rb +27 -0
  38. data/document/if-ALCATEL7750.md +48 -0
  39. data/document/if-C7609.md +47 -0
  40. data/document/if-CR16010H-F.md +300 -0
  41. data/document/if-CR16018-F.md +300 -0
  42. data/document/if-CR19000-20.md +300 -0
  43. data/document/if-CRS-16.md +47 -0
  44. data/document/if-CX600-X16A.md +349 -0
  45. data/document/if-CX600-X8A.md +349 -0
  46. data/document/if-M6000-16E.md +652 -0
  47. data/document/if-M6000-18S.md +846 -0
  48. data/document/if-M6000-8.md +653 -0
  49. data/document/if-M6000-8E.md +653 -0
  50. data/document/if-MA5200G-8.md +357 -0
  51. data/document/if-ME60-16.md +357 -0
  52. data/document/if-ME60-X16.md +357 -0
  53. data/document/if-NE40E-X16.md +357 -0
  54. data/document/if-NE40E-X16A.md +357 -0
  55. data/document/if-NE40E-X8.md +357 -0
  56. data/document/if-NE40E.md +357 -0
  57. data/document/if-NE5000E-20.md +357 -0
  58. data/document/if-NE5000E-X16.md +357 -0
  59. data/document/if-NE5000E-X16A.md +357 -0
  60. data/document/if-NE8000E-X8.md +357 -0
  61. data/document/if-NE80E.md +357 -0
  62. data/document/if-NE8100-X8.md +357 -0
  63. data/document/if-Nokia7750.md +48 -0
  64. data/document/if-T8000-18.md +653 -0
  65. data/document/if-V6000.md +663 -0
  66. data/document/if-VNE9000.md +357 -0
  67. data/document/if-ZXCTN9000-18EA.md +762 -0
  68. data/document/if-ZXCTN9000-8EA.md +762 -0
  69. data/document/lic-M6000-16E.md +28 -0
  70. data/document/lic-M6000-18S.md +28 -0
  71. data/document/lic-M6000-8.md +28 -0
  72. data/document/lic-M6000-8E.md +28 -0
  73. data/document/lic-MA5200G-8.md +27 -0
  74. data/document/lic-ME60-16.md +27 -0
  75. data/document/lic-ME60-X16.md +27 -0
  76. data/document/lic-NE40E-X16.md +27 -0
  77. data/document/lic-NE40E-X16A.md +27 -0
  78. data/document/lic-NE40E-X8.md +27 -0
  79. data/document/log-M6000-16E.md +36 -0
  80. data/document/log-M6000-18S.md +36 -0
  81. data/document/log-M6000-8.md +36 -0
  82. data/document/log-M6000-8E.md +36 -0
  83. data/document/log-MA5200G-8.md +61 -0
  84. data/document/log-ME60-16.md +61 -0
  85. data/document/log-ME60-X16.md +61 -0
  86. data/document/log-NE40E-X16.md +61 -0
  87. data/document/log-NE40E-X16A.md +61 -0
  88. data/document/log-NE40E-X8.md +61 -0
  89. data/document/log-NE40E.md +61 -0
  90. data/document/log-NE5000E-20.md +61 -0
  91. data/document/log-NE5000E-X16.md +61 -0
  92. data/document/log-NE5000E-X16A.md +61 -0
  93. data/document/log-NE80E.md +61 -0
  94. data/document/nat-CR16010H-F.md +27 -0
  95. data/document/nat-CR16018-F.md +27 -0
  96. data/document/nat-M6000-16E.md +27 -0
  97. data/document/nat-M6000-18S.md +27 -0
  98. data/document/nat-M6000-8.md +27 -0
  99. data/document/nat-M6000-8E.md +27 -0
  100. data/document/nat-ME60-16.md +44 -0
  101. data/document/nat-ME60-X16.md +44 -0
  102. data/document/nat-NE40E-X16.md +44 -0
  103. data/document/nat-NE40E-X16A.md +44 -0
  104. data/document/policy-M6000-16E.md +13 -0
  105. data/document/policy-M6000-18S.md +13 -0
  106. data/document/policy-M6000-8.md +13 -0
  107. data/document/policy-M6000-8E.md +13 -0
  108. data/document/policy-MA5200G-8.md +87 -0
  109. data/document/policy-ME60-16.md +87 -0
  110. data/document/policy-ME60-X16.md +87 -0
  111. data/document/policy-NE40E-X16.md +87 -0
  112. data/document/policy-NE40E-X16A.md +87 -0
  113. data/document/policy-NE40E-X8.md +87 -0
  114. data/document/policy-NE40E.md +87 -0
  115. data/document/policy-NE5000E-20.md +87 -0
  116. data/document/policy-NE5000E-X16.md +87 -0
  117. data/document/policy-NE5000E-X16A.md +87 -0
  118. data/document/policy-NE80E.md +87 -0
  119. data/document/pool-M6000-16E.md +126 -0
  120. data/document/pool-M6000-18S.md +126 -0
  121. data/document/pool-M6000-8.md +126 -0
  122. data/document/pool-M6000-8E.md +126 -0
  123. data/document/pool-MA5200G-8.md +138 -0
  124. data/document/pool-ME60-16.md +138 -0
  125. data/document/pool-ME60-X16.md +138 -0
  126. data/document/pool-NE40E-X16.md +138 -0
  127. data/document/pool-NE40E-X16A.md +138 -0
  128. data/document/pool-NE40E-X8.md +138 -0
  129. data/document/pool-NE40E.md +138 -0
  130. data/document/pool-NE80E.md +138 -0
  131. data/document/static-CR16010H-F.md +60 -0
  132. data/document/static-CR16018-F.md +60 -0
  133. data/document/static-CR19000-20.md +60 -0
  134. data/document/static-CX600-X16A.md +26 -0
  135. data/document/static-CX600-X8A.md +26 -0
  136. data/document/static-M6000-16E.md +104 -0
  137. data/document/static-M6000-18S.md +104 -0
  138. data/document/static-M6000-8.md +104 -0
  139. data/document/static-M6000-8E.md +104 -0
  140. data/document/static-MA5200G-8.md +82 -0
  141. data/document/static-ME60-16.md +82 -0
  142. data/document/static-ME60-X16.md +82 -0
  143. data/document/static-NE40E-X16.md +82 -0
  144. data/document/static-NE40E-X16A.md +81 -0
  145. data/document/static-NE40E-X8.md +82 -0
  146. data/document/static-NE40E.md +67 -0
  147. data/document/static-NE5000E-20.md +67 -0
  148. data/document/static-NE5000E-X16.md +67 -0
  149. data/document/static-NE5000E-X16A.md +67 -0
  150. data/document/static-NE8000E-X8.md +26 -0
  151. data/document/static-NE80E.md +67 -0
  152. data/document/static-NE8100-X8.md +26 -0
  153. data/document/static-T8000-18.md +34 -0
  154. data/document/static-ZXCTN9000-18EA.md +34 -0
  155. data/document/static-ZXCTN9000-8EA.md +34 -0
  156. data/document/system-M6000-16E.md +75 -0
  157. data/document/system-M6000-18S.md +76 -0
  158. data/document/system-M6000-8.md +75 -0
  159. data/document/system-M6000-8E.md +75 -0
  160. data/document/system-MA5200G-8.md +51 -0
  161. data/document/system-ME60-16.md +51 -0
  162. data/document/system-ME60-X16.md +51 -0
  163. data/document/system-NE40E-X16.md +51 -0
  164. data/document/system-NE40E-X16A.md +51 -0
  165. data/document/system-NE40E-X8.md +51 -0
  166. data/document/system-NE40E.md +51 -0
  167. data/document/system-NE5000E-20.md +51 -0
  168. data/document/system-NE5000E-X16.md +51 -0
  169. data/document/system-NE5000E-X16A.md +51 -0
  170. data/document/system-NE80E.md +51 -0
  171. data/document/telnet.md +332 -0
  172. data/network.rb +24 -0
  173. data/utility/ipv4_address.rb +266 -0
  174. data/utility/ipv6_address.rb +201 -0
  175. data/utility/mac_address.rb +77 -0
  176. data/utility/netmerge.rb +46 -0
  177. data/utility/route.rb +79 -0
  178. data/utility/whitelist.rb +21 -0
  179. metadata +258 -0
@@ -0,0 +1,204 @@
1
+
2
+ # NE40E 访问控制列表
3
+
4
+ ```ruby
5
+ @sign << ['NE40E', 'ACL']
6
+ @sign << ['NE40E', 'resort']
7
+ @sign << ['NE40E', 'detect_adv']
8
+ @sign << ['NE40E', 'gen_rule']
9
+
10
+ module NE40E
11
+ module_function
12
+
13
+ def ACL config
14
+ table = {}
15
+ number = nil
16
+ config.split("\n").each do|line|
17
+ number = line.split('number')[1].strip.to_i if line.include?('acl number') or line.include?('acl ipv6 number')
18
+ table[number] ||= {}
19
+ if line.include?('rule')
20
+ rule = line.split(' ')
21
+ table[number][rule[1].to_i] = rule[2..-1]
22
+ end
23
+ end
24
+ table.delete(nil)
25
+ return table
26
+ end
27
+
28
+ # 重排ACL序号,只对纯文本编排,注意最末行
29
+ def resort text, index # {[old,old]=>new}
30
+ packs,newlist = {},[]
31
+ index.each do|is,ni| packs[ni] = [] end
32
+ text.split("\n").each do|line|
33
+ items = line.split(' ')
34
+ id = items[1].to_i
35
+ index.each do|is,ni|
36
+ packs[ni] << items[2..-1].join(' ') if (is[0]..is[1]).include?(id)
37
+ end
38
+ newlist << "undo rule #{id}"
39
+ end
40
+ packs.each do|ni,pack|
41
+ pack.sort.each_with_index do|rule, si|
42
+ newlist << "rule #{ni.to_i+si.to_i} #{rule}"
43
+ end
44
+ end
45
+ return newlist.join("\n")
46
+ end
47
+
48
+ # INTEGER<1000-1999> Interface access-list(add to current using rules)
49
+ # INTEGER<10000-10999> MPLS access list (add to current using rules)
50
+ # INTEGER<2000-2999> Basic access-list(add to current using rules)
51
+ # INTEGER<3000-3999> Advanced access-list(add to current using rules)
52
+ # INTEGER<4000-4999> Specify a L2 ACL group(add to current using rules)
53
+ # ip-pool Specify IP pool configuration
54
+ # ipv6 ACL IPv6
55
+ # name Specify a named ACL
56
+ # number Specify a numbered ACL
57
+
58
+ PORTS = {
59
+ 137 => 'netbios-ns',
60
+ 138 => 'netbios-dgm',
61
+ 139 => 'netbios-ssn',
62
+ 19 => 'CHARgen',
63
+ 179 => 'bgp',
64
+ 514 => 'cmd',
65
+ 13 => 'daytime',
66
+ 9 => 'discard',
67
+ 53 => 'domain',
68
+ 7 => 'echo',
69
+ 512 => 'exec',
70
+ 79 => 'finger',
71
+ 21 => 'ftp',
72
+ 20 => 'ftp-data',
73
+ 70 => 'gopher',
74
+ 101 => 'hostname',
75
+ 194 => 'irc',
76
+ 543 => 'klogin',
77
+ 544 => 'kshell',
78
+ 513 => 'login',
79
+ 515 => 'lpd',
80
+ 119 => 'nntp',
81
+ 109 => 'pop2',
82
+ 110 => 'pop3',
83
+ 25 => 'smtp',
84
+ 111 => 'sunrpc',
85
+ 49 => 'tacacs',
86
+ 517 => 'talk',
87
+ 23 => 'telnet',
88
+ 37 => 'time',
89
+ 540 => 'uucp',
90
+ 43 => 'whois',
91
+ 80 => 'www'
92
+ }
93
+
94
+ # acl-adv rule
95
+ def detect_adv rule,index=nil
96
+ words = rule.instance_of?(String) ? rule.split(' ') : rule # text or array
97
+ # words: <action> <protocol> [<src>] [<dst>] [<tail>]
98
+ # <src> := [ source <sip> <smk> ] [ source-port [[eq|gt|lt <spt>]|[range <spt1> <spt2>]] ]
99
+ # <dst> := [ destination <dip> <dmk>] [ destination-port [[eq|gt|lt <dpt>]|[range <dpt1> <dpt2>]] ]
100
+ # <tail> := "PENDING"
101
+ ritle = {}
102
+ ritle['index'] = index if index
103
+ action,protocol = words[0..1]
104
+ ritle['action'] = action
105
+ ritle['protocol'] = protocol
106
+ ['source','destination'].each do|edge|
107
+ if words.include?(edge)
108
+ edge_ip = words[words.index(edge)+1]
109
+ unless edge_ip=='any'
110
+ if edge_ip.include?(':')
111
+ start_ip, ei_amask = IP.v6(edge_ip)
112
+ else
113
+ ei_amask_str = words[words.index(edge)+2]
114
+ ei_amask_str = '0.0.0.0' if ei_amask_str == '0'
115
+ start_ip,ei_amask = IP.v4(edge_ip),IP.v4(ei_amask_str)
116
+ end
117
+ end_ip = start_ip.clone + ei_amask.number
118
+ ritle[edge] = [start_ip.to_s, end_ip.to_s]
119
+ end
120
+ end
121
+ end
122
+ ['source-port', 'destination-port'].each do|port|
123
+ if words.include?(port)
124
+ op = words[words.index(port)+1]
125
+ range = case op
126
+ when 'range'
127
+ a, b = words[words.index(port)+2], words[words.index(port)+3]
128
+ a = PORTS.key(a) ? PORTS.key(a) : a.to_i
129
+ b = PORTS.key(b) ? PORTS.key(b) : b.to_i
130
+ [ a, b ]
131
+ when 'lt'
132
+ a = words[words.index(port)+2]
133
+ a = PORTS.key(a) ? PORTS.key(a) : a.to_i
134
+ [ 0, a ]
135
+ when 'gt'
136
+ a = words[words.index(port)+2]
137
+ a = PORTS.key(a) ? PORTS.key(a) : a.to_i
138
+ [ 65535, a ]
139
+ when 'eq'
140
+ a = words[words.index(port)+2]
141
+ a = PORTS.key(a) ? PORTS.key(a) : a.to_i
142
+ [ a, a ]
143
+ end.sort
144
+ ritle[port] = range
145
+ end
146
+ end
147
+ # TODO: tail
148
+ return ritle
149
+ end
150
+
151
+ # 查询规则1#
152
+ def in_range? ritle, target
153
+ tip = IP.v4(target[:ip])
154
+ tnum = tip.number
155
+ if ritle["destination"] && ritle["destination-port"]
156
+ si,ei = ritle["destination"].map{|i|IP.v4(i).number}
157
+ sp,ep = ritle["destination-port"]
158
+ return ritle if (si..ei).include?(tnum) && (sp..ep).include?(target[:port]) && ritle['action']==target[:action]
159
+ end
160
+ return nil
161
+ end
162
+
163
+ # 查询规则2#
164
+ def list_in_range? list, target
165
+ tip = IP.v4(target[:ip])
166
+ tnum = tip.number
167
+ set = []
168
+ list.each do|ritle|
169
+ if ritle["destination"] && ritle["destination-port"]
170
+ si,ei = ritle["destination"].map{|i|IP.v4(i).number}
171
+ sp,ep = ritle["destination-port"]
172
+ set << ritle if (si..ei).include?(tnum) && (sp..ep).include?(target[:port]) && ritle['action']==target[:action]
173
+ end
174
+ end
175
+ return set
176
+ end
177
+
178
+ # 生成规则:
179
+ # options = {
180
+ # index: 107,
181
+ # action: 'deny',
182
+ # protocol: 'tcp',
183
+ # sip: '1.1.1.1',
184
+ # sport: 80,
185
+ # dip: '2.2.2.2',
186
+ # dport: 443
187
+ # }
188
+ def gen_rule options
189
+ rule = ['rule']
190
+ return {'conf-error'=>"缺少必要参数:规则索引"} unless options[:index]
191
+ return {'conf-error'=>"缺少必要参数:动作"} unless options[:action]
192
+ return {'conf-error'=>"缺少必要参数:协议"} unless options[:protocol]
193
+ return {'runtime-error'=>"规则空位不足"} if options[:index]=='no slot'
194
+ rule << options[:index]
195
+ rule << options[:action]
196
+ rule << options[:protocol]
197
+ options[:sip] and rule << "source #{options[:sip]}"
198
+ options[:sport] and rule << "source-port eq #{options[:sport]}"
199
+ options[:dip] and rule << "destination #{options[:dip]}"
200
+ options[:dport] and rule << "destination-port eq #{options[:dport]}"
201
+ return {"operation"=>rule.join(" ")}
202
+ end
203
+ end
204
+ ```
@@ -0,0 +1,25 @@
1
+
2
+ # NE5000E-20 访问控制列表
3
+
4
+ ```ruby
5
+ @sign << ['NE5000E-20', 'ACL']
6
+
7
+ module NE5000E_20
8
+ module_function
9
+
10
+ def ACL config
11
+ table = {}
12
+ number = nil
13
+ config.split("\n").each do|line|
14
+ number = line.split('number')[1].strip.to_i if line.include?('acl number') or line.include?('acl ipv6 number')
15
+ table[number] ||= {}
16
+ if line.include?('rule')
17
+ rule = line.split(' ')
18
+ table[number][rule[1].to_i] = rule[2..-1]
19
+ end
20
+ end
21
+ table.delete(nil)
22
+ return table
23
+ end
24
+ end
25
+ ```
@@ -0,0 +1,25 @@
1
+
2
+ # NE5000E-X16 访问控制列表
3
+
4
+ ```ruby
5
+ @sign << ['NE5000E-X16', 'ACL']
6
+
7
+ module NE5000E_X16
8
+ module_function
9
+
10
+ def ACL config
11
+ table = {}
12
+ number = nil
13
+ config.split("\n").each do|line|
14
+ number = line.split('number')[1].strip.to_i if line.include?('acl number') or line.include?('acl ipv6 number')
15
+ table[number] ||= {}
16
+ if line.include?('rule')
17
+ rule = line.split(' ')
18
+ table[number][rule[1].to_i] = rule[2..-1]
19
+ end
20
+ end
21
+ table.delete(nil)
22
+ return table
23
+ end
24
+ end
25
+ ```
@@ -0,0 +1,25 @@
1
+
2
+ # NE5000E-X16A 访问控制列表
3
+
4
+ ```ruby
5
+ @sign << ['NE5000E-X16A', 'ACL']
6
+
7
+ module NE5000E_X16A
8
+ module_function
9
+
10
+ def ACL config
11
+ table = {}
12
+ number = nil
13
+ config.split("\n").each do|line|
14
+ number = line.split('number')[1].strip.to_i if line.include?('acl number') or line.include?('acl ipv6 number')
15
+ table[number] ||= {}
16
+ if line.include?('rule')
17
+ rule = line.split(' ')
18
+ table[number][rule[1].to_i] = rule[2..-1]
19
+ end
20
+ end
21
+ table.delete(nil)
22
+ return table
23
+ end
24
+ end
25
+ ```
@@ -0,0 +1,204 @@
1
+
2
+ # NE80E 访问控制列表
3
+
4
+ ```ruby
5
+ @sign << ['NE80E', 'ACL']
6
+ @sign << ['NE80E', 'resort']
7
+ @sign << ['NE80E', 'detect_adv']
8
+ @sign << ['NE80E', 'gen_rule']
9
+
10
+ module NE80E
11
+ module_function
12
+
13
+ def ACL config
14
+ table = {}
15
+ number = nil
16
+ config.split("\n").each do|line|
17
+ number = line.split('number')[1].strip.to_i if line.include?('acl number') or line.include?('acl ipv6 number')
18
+ table[number] ||= {}
19
+ if line.include?('rule')
20
+ rule = line.split(' ')
21
+ table[number][rule[1].to_i] = rule[2..-1]
22
+ end
23
+ end
24
+ table.delete(nil)
25
+ return table
26
+ end
27
+
28
+ # 重排ACL序号,只对纯文本编排,注意最末行
29
+ def resort text, index # {[old,old]=>new}
30
+ packs,newlist = {},[]
31
+ index.each do|is,ni| packs[ni] = [] end
32
+ text.split("\n").each do|line|
33
+ items = line.split(' ')
34
+ id = items[1].to_i
35
+ index.each do|is,ni|
36
+ packs[ni] << items[2..-1].join(' ') if (is[0]..is[1]).include?(id)
37
+ end
38
+ newlist << "undo rule #{id}"
39
+ end
40
+ packs.each do|ni,pack|
41
+ pack.sort.each_with_index do|rule, si|
42
+ newlist << "rule #{ni.to_i+si.to_i} #{rule}"
43
+ end
44
+ end
45
+ return newlist.join("\n")
46
+ end
47
+
48
+ # INTEGER<1000-1999> Interface access-list(add to current using rules)
49
+ # INTEGER<10000-10999> MPLS access list (add to current using rules)
50
+ # INTEGER<2000-2999> Basic access-list(add to current using rules)
51
+ # INTEGER<3000-3999> Advanced access-list(add to current using rules)
52
+ # INTEGER<4000-4999> Specify a L2 ACL group(add to current using rules)
53
+ # ip-pool Specify IP pool configuration
54
+ # ipv6 ACL IPv6
55
+ # name Specify a named ACL
56
+ # number Specify a numbered ACL
57
+
58
+ PORTS = {
59
+ 137 => 'netbios-ns',
60
+ 138 => 'netbios-dgm',
61
+ 139 => 'netbios-ssn',
62
+ 19 => 'CHARgen',
63
+ 179 => 'bgp',
64
+ 514 => 'cmd',
65
+ 13 => 'daytime',
66
+ 9 => 'discard',
67
+ 53 => 'domain',
68
+ 7 => 'echo',
69
+ 512 => 'exec',
70
+ 79 => 'finger',
71
+ 21 => 'ftp',
72
+ 20 => 'ftp-data',
73
+ 70 => 'gopher',
74
+ 101 => 'hostname',
75
+ 194 => 'irc',
76
+ 543 => 'klogin',
77
+ 544 => 'kshell',
78
+ 513 => 'login',
79
+ 515 => 'lpd',
80
+ 119 => 'nntp',
81
+ 109 => 'pop2',
82
+ 110 => 'pop3',
83
+ 25 => 'smtp',
84
+ 111 => 'sunrpc',
85
+ 49 => 'tacacs',
86
+ 517 => 'talk',
87
+ 23 => 'telnet',
88
+ 37 => 'time',
89
+ 540 => 'uucp',
90
+ 43 => 'whois',
91
+ 80 => 'www'
92
+ }
93
+
94
+ # acl-adv rule
95
+ def detect_adv rule,index=nil
96
+ words = rule.instance_of?(String) ? rule.split(' ') : rule # text or array
97
+ # words: <action> <protocol> [<src>] [<dst>] [<tail>]
98
+ # <src> := [ source <sip> <smk> ] [ source-port [[eq|gt|lt <spt>]|[range <spt1> <spt2>]] ]
99
+ # <dst> := [ destination <dip> <dmk>] [ destination-port [[eq|gt|lt <dpt>]|[range <dpt1> <dpt2>]] ]
100
+ # <tail> := "PENDING"
101
+ ritle = {}
102
+ ritle['index'] = index if index
103
+ action,protocol = words[0..1]
104
+ ritle['action'] = action
105
+ ritle['protocol'] = protocol
106
+ ['source','destination'].each do|edge|
107
+ if words.include?(edge)
108
+ edge_ip = words[words.index(edge)+1]
109
+ unless edge_ip=='any'
110
+ if edge_ip.include?(':')
111
+ start_ip, ei_amask = IP.v6(edge_ip)
112
+ else
113
+ ei_amask_str = words[words.index(edge)+2]
114
+ ei_amask_str = '0.0.0.0' if ei_amask_str == '0'
115
+ start_ip,ei_amask = IP.v4(edge_ip),IP.v4(ei_amask_str)
116
+ end
117
+ end_ip = start_ip.clone + ei_amask.number
118
+ ritle[edge] = [start_ip.to_s, end_ip.to_s]
119
+ end
120
+ end
121
+ end
122
+ ['source-port', 'destination-port'].each do|port|
123
+ if words.include?(port)
124
+ op = words[words.index(port)+1]
125
+ range = case op
126
+ when 'range'
127
+ a, b = words[words.index(port)+2], words[words.index(port)+3]
128
+ a = PORTS.key(a) ? PORTS.key(a) : a.to_i
129
+ b = PORTS.key(b) ? PORTS.key(b) : b.to_i
130
+ [ a, b ]
131
+ when 'lt'
132
+ a = words[words.index(port)+2]
133
+ a = PORTS.key(a) ? PORTS.key(a) : a.to_i
134
+ [ 0, a ]
135
+ when 'gt'
136
+ a = words[words.index(port)+2]
137
+ a = PORTS.key(a) ? PORTS.key(a) : a.to_i
138
+ [ 65535, a ]
139
+ when 'eq'
140
+ a = words[words.index(port)+2]
141
+ a = PORTS.key(a) ? PORTS.key(a) : a.to_i
142
+ [ a, a ]
143
+ end.sort
144
+ ritle[port] = range
145
+ end
146
+ end
147
+ # TODO: tail
148
+ return ritle
149
+ end
150
+
151
+ # 查询规则1#
152
+ def in_range? ritle, target
153
+ tip = IP.v4(target[:ip])
154
+ tnum = tip.number
155
+ if ritle["destination"] && ritle["destination-port"]
156
+ si,ei = ritle["destination"].map{|i|IP.v4(i).number}
157
+ sp,ep = ritle["destination-port"]
158
+ return ritle if (si..ei).include?(tnum) && (sp..ep).include?(target[:port]) && ritle['action']==target[:action]
159
+ end
160
+ return nil
161
+ end
162
+
163
+ # 查询规则2#
164
+ def list_in_range? list, target
165
+ tip = IP.v4(target[:ip])
166
+ tnum = tip.number
167
+ set = []
168
+ list.each do|ritle|
169
+ if ritle["destination"] && ritle["destination-port"]
170
+ si,ei = ritle["destination"].map{|i|IP.v4(i).number}
171
+ sp,ep = ritle["destination-port"]
172
+ set << ritle if (si..ei).include?(tnum) && (sp..ep).include?(target[:port]) && ritle['action']==target[:action]
173
+ end
174
+ end
175
+ return set
176
+ end
177
+
178
+ # 生成规则:
179
+ # options = {
180
+ # index: 107,
181
+ # action: 'deny',
182
+ # protocol: 'tcp',
183
+ # sip: '1.1.1.1',
184
+ # sport: 80,
185
+ # dip: '2.2.2.2',
186
+ # dport: 443
187
+ # }
188
+ def gen_rule options
189
+ rule = ['rule']
190
+ return {'conf-error'=>"缺少必要参数:规则索引"} unless options[:index]
191
+ return {'conf-error'=>"缺少必要参数:动作"} unless options[:action]
192
+ return {'conf-error'=>"缺少必要参数:协议"} unless options[:protocol]
193
+ return {'runtime-error'=>"规则空位不足"} if options[:index]=='no slot'
194
+ rule << options[:index]
195
+ rule << options[:action]
196
+ rule << options[:protocol]
197
+ options[:sip] and rule << "source #{options[:sip]}"
198
+ options[:sport] and rule << "source-port eq #{options[:sport]}"
199
+ options[:dip] and rule << "destination #{options[:dip]}"
200
+ options[:dport] and rule << "destination-port eq #{options[:dport]}"
201
+ return {"operation"=>rule.join(" ")}
202
+ end
203
+ end
204
+ ```
@@ -0,0 +1,25 @@
1
+
2
+ # CR16010H-F BGP
3
+
4
+ ```ruby
5
+ @sign << ['CR16010H-F', '宣告网段解析']
6
+
7
+ module CR16010H_F
8
+ module_function
9
+
10
+ def 宣告网段解析 配置散列
11
+ ranges = []
12
+ 配置散列['bgp'].first.split("\n").each do|line|
13
+ if line.include?('network ') && line.split(' ').size > 2
14
+ ip1,ip2 = line.split(' ')[1..2]
15
+ ip, mask = line.split(' ')[1].include?(':') ? IP.v6("#{ip1}/#{ip2}") : IP.v4("#{ip1}/#{ip2}")
16
+ network = ip.network_with mask
17
+ start_ip, end_ip = ip.range_with mask
18
+ ranges << [ 'bgp', network.to_s, end_ip.to_s ]
19
+ end
20
+ # puts [hostname]+line.split(' ') if line.include?('network ') && line.split(' ').size == 2
21
+ end
22
+ return ranges
23
+ end
24
+ end
25
+ ```
@@ -0,0 +1,25 @@
1
+
2
+ # CR16018-F BGP
3
+
4
+ ```ruby
5
+ @sign << ['CR16018-F', '宣告网段解析']
6
+
7
+ module CR16018_F
8
+ module_function
9
+
10
+ def 宣告网段解析 配置散列
11
+ ranges = []
12
+ 配置散列['bgp'].first.split("\n").each do|line|
13
+ if line.include?('network ') && line.split(' ').size > 2
14
+ ip1,ip2 = line.split(' ')[1..2]
15
+ ip, mask = line.split(' ')[1].include?(':') ? IP.v6("#{ip1}/#{ip2}") : IP.v4("#{ip1}/#{ip2}")
16
+ network = ip.network_with mask
17
+ start_ip, end_ip = ip.range_with mask
18
+ ranges << [ 'bgp', network.to_s, end_ip.to_s ]
19
+ end
20
+ # puts [hostname]+line.split(' ') if line.include?('network ') && line.split(' ').size == 2
21
+ end
22
+ return ranges
23
+ end
24
+ end
25
+ ```
@@ -0,0 +1,25 @@
1
+
2
+ # CR19000-20 BGP
3
+
4
+ ```ruby
5
+ @sign << ['CR19000-20', '宣告网段解析']
6
+
7
+ module CR19000_20
8
+ module_function
9
+
10
+ def 宣告网段解析 配置散列
11
+ ranges = []
12
+ 配置散列['bgp'].first.split("\n").each do|line|
13
+ if line.include?('network ') && line.split(' ').size > 2
14
+ ip1,ip2 = line.split(' ')[1..2]
15
+ ip, mask = line.split(' ')[1].include?(':') ? IP.v6("#{ip1}/#{ip2}") : IP.v4("#{ip1}/#{ip2}")
16
+ network = ip.network_with mask
17
+ start_ip, end_ip = ip.range_with mask
18
+ ranges << [ 'bgp', network.to_s, end_ip.to_s ]
19
+ end
20
+ # puts [hostname]+line.split(' ') if line.include?('network ') && line.split(' ').size == 2
21
+ end
22
+ return ranges
23
+ end
24
+ end
25
+ ```
@@ -0,0 +1,25 @@
1
+
2
+ # M6000-16E BGP
3
+
4
+ ```ruby
5
+ @sign << ['M6000-16E', '宣告网段解析']
6
+
7
+ module M6000_16E
8
+ module_function
9
+
10
+ def 宣告网段解析 配置散列
11
+ ranges = []
12
+ 配置散列['bgp'].split("\n").each do|line|
13
+ if line.include?('network ')
14
+ items = line.split(" ")
15
+ ip1,ip2 = items[1].include?(':') ? items[1].split("/") : items[1..2]
16
+ ip, mask = ip1.include?(":") ? IP.v6("#{ip1}/#{ip2}") : IP.v4("#{ip1}/#{ip2}")
17
+ network = ip.network_with mask
18
+ start_ip, end_ip = ip.range_with mask
19
+ ranges << [ 'bgp', network.to_s, end_ip.to_s ]
20
+ end
21
+ end
22
+ return ranges
23
+ end
24
+ end
25
+ ```
@@ -0,0 +1,25 @@
1
+
2
+ # M6000-18S BGP
3
+
4
+ ```ruby
5
+ @sign << ['M6000-18S', '宣告网段解析']
6
+
7
+ module M6000_18S
8
+ module_function
9
+
10
+ def 宣告网段解析 配置散列
11
+ ranges = []
12
+ 配置散列['bgp'].split("\n").each do|line|
13
+ if line.include?('network ')
14
+ items = line.split(" ")
15
+ ip1,ip2 = items[1].include?(':') ? items[1].split("/") : items[1..2]
16
+ ip, mask = ip1.include?(":") ? IP.v6("#{ip1}/#{ip2}") : IP.v4("#{ip1}/#{ip2}")
17
+ network = ip.network_with mask
18
+ start_ip, end_ip = ip.range_with mask
19
+ ranges << [ 'bgp', network.to_s, end_ip.to_s ]
20
+ end
21
+ end
22
+ return ranges
23
+ end
24
+ end
25
+ ```
@@ -0,0 +1,25 @@
1
+
2
+ # M6000-8 BGP
3
+
4
+ ```ruby
5
+ @sign << ['M6000-8', '宣告网段解析']
6
+
7
+ module M6000_8
8
+ module_function
9
+
10
+ def 宣告网段解析 配置散列
11
+ ranges = []
12
+ 配置散列['bgp'].split("\n").each do|line|
13
+ if line.include?('network ')
14
+ items = line.split(" ")
15
+ ip1,ip2 = items[1].include?(':') ? items[1].split("/") : items[1..2]
16
+ ip, mask = ip1.include?(":") ? IP.v6("#{ip1}/#{ip2}") : IP.v4("#{ip1}/#{ip2}")
17
+ network = ip.network_with mask
18
+ start_ip, end_ip = ip.range_with mask
19
+ ranges << [ 'bgp', network.to_s, end_ip.to_s ]
20
+ end
21
+ end
22
+ return ranges
23
+ end
24
+ end
25
+ ```
@@ -0,0 +1,25 @@
1
+
2
+ # M6000-8E BGP
3
+
4
+ ```ruby
5
+ @sign << ['M6000-8E', '宣告网段解析']
6
+
7
+ module M6000_8E
8
+ module_function
9
+
10
+ def 宣告网段解析 配置散列
11
+ ranges = []
12
+ 配置散列['bgp'].split("\n").each do|line|
13
+ if line.include?('network ')
14
+ items = line.split(" ")
15
+ ip1,ip2 = items[1].include?(':') ? items[1].split("/") : items[1..2]
16
+ ip, mask = ip1.include?(":") ? IP.v6("#{ip1}/#{ip2}") : IP.v4("#{ip1}/#{ip2}")
17
+ network = ip.network_with mask
18
+ start_ip, end_ip = ip.range_with mask
19
+ ranges << [ 'bgp', network.to_s, end_ip.to_s ]
20
+ end
21
+ end
22
+ return ranges
23
+ end
24
+ end
25
+ ```
@@ -0,0 +1,25 @@
1
+
2
+ # MA5200G-8 BGP
3
+
4
+ ```ruby
5
+ @sign << ['MA5200G-8', '宣告网段解析']
6
+
7
+ module MA5200G_8
8
+ module_function
9
+
10
+ def 宣告网段解析 配置散列
11
+ ranges = []
12
+ 配置散列['bgp'].first.split("\n").each do|line|
13
+ if line.include?('network ') && line.split(' ').size > 2
14
+ ip1,ip2 = line.split(' ')[1..2]
15
+ ip, mask = line.split(' ')[1].include?(':') ? IP.v6("#{ip1}/#{ip2}") : IP.v4("#{ip1}/#{ip2}")
16
+ network = ip.network_with mask
17
+ start_ip, end_ip = ip.range_with mask
18
+ ranges << [ 'bgp', network.to_s, end_ip.to_s ]
19
+ end
20
+ # puts [hostname]+line.split(' ') if line.include?('network ') && line.split(' ').size == 2
21
+ end
22
+ return ranges
23
+ end
24
+ end
25
+ ```