network-utility 1.1.21 → 1.1.23
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.
- checksums.yaml +4 -4
- data/document/config.md +70 -14
- data/network.rb +1 -1
- data/utility/ipv4_address.rb +29 -2
- data/utility/ipv6_address.rb +31 -3
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 3c7c31820c5da28e7b349b23bf0f9d8c39b107ea3f57534f34685b95247b9e60
|
4
|
+
data.tar.gz: '0898de3553f101c901ab1fae634c3c83a77201a2400e6fe6d16f4dcbc9bab1d5'
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: dba1105b160ac6a7079d435587d4183f1879c2fdbaa6cadd223e6a767f1ff5bc7b4dae9aa32e22a4b0f474ef11a1274d44f6a7b43db32d48dff8eadaef23fc3c
|
7
|
+
data.tar.gz: 92b33a3315d2d5fd07389de6c5018fa8ce3041761198bf6cc5cb28ef10592973fe880c2f5ec49ddb63860466041e7133ddce20c8418d52e7ce28d73660e7b3d9
|
data/document/config.md
CHANGED
@@ -110,7 +110,11 @@ module CX600_X8A
|
|
110
110
|
begin
|
111
111
|
raw.split("\n")
|
112
112
|
rescue
|
113
|
-
|
113
|
+
begin
|
114
|
+
raw = braw.force_encoding('GBK').encode('UTF-8')
|
115
|
+
rescue
|
116
|
+
raw = braw.force_encoding('ASCII-8BIT')
|
117
|
+
end
|
114
118
|
end
|
115
119
|
cfg = {}
|
116
120
|
hostname = guards[0] || raw.split("\n").find{|line|line.include?("sysname ")}.to_s.split("sysname ")[1]
|
@@ -145,7 +149,11 @@ module CX600_X16A
|
|
145
149
|
begin
|
146
150
|
raw.split("\n")
|
147
151
|
rescue
|
148
|
-
|
152
|
+
begin
|
153
|
+
raw = braw.force_encoding('GBK').encode('UTF-8')
|
154
|
+
rescue
|
155
|
+
raw = braw.force_encoding('ASCII-8BIT')
|
156
|
+
end
|
149
157
|
end
|
150
158
|
cfg = {}
|
151
159
|
hostname = guards[0] || raw.split("\n").find{|line|line.include?("sysname ")}.to_s.split("sysname ")[1]
|
@@ -180,7 +188,11 @@ module MA5200G_8
|
|
180
188
|
begin
|
181
189
|
raw.split("\n")
|
182
190
|
rescue
|
183
|
-
|
191
|
+
begin
|
192
|
+
raw = braw.force_encoding('GBK').encode('UTF-8')
|
193
|
+
rescue
|
194
|
+
raw = braw.force_encoding('ASCII-8BIT')
|
195
|
+
end
|
184
196
|
end
|
185
197
|
cfg = {}
|
186
198
|
hostname = guards[0] || raw.split("\n").find{|line|line.include?("sysname ")}.to_s.split("sysname ")[1]
|
@@ -274,7 +286,11 @@ module ME60_16
|
|
274
286
|
begin
|
275
287
|
raw.split("\n")
|
276
288
|
rescue
|
277
|
-
|
289
|
+
begin
|
290
|
+
raw = braw.force_encoding('GBK').encode('UTF-8')
|
291
|
+
rescue
|
292
|
+
raw = braw.force_encoding('ASCII-8BIT')
|
293
|
+
end
|
278
294
|
end
|
279
295
|
cfg = {}
|
280
296
|
hostname = guards[0] || raw.split("\n").find{|line|line.include?("sysname ")}.to_s.split("sysname ")[1]
|
@@ -311,7 +327,11 @@ module ME60_X16
|
|
311
327
|
begin
|
312
328
|
raw.split("\n")
|
313
329
|
rescue
|
314
|
-
|
330
|
+
begin
|
331
|
+
raw = braw.force_encoding('GBK').encode('UTF-8')
|
332
|
+
rescue
|
333
|
+
raw = braw.force_encoding('ASCII-8BIT')
|
334
|
+
end
|
315
335
|
end
|
316
336
|
cfg = {}
|
317
337
|
hostname = guards[0] || raw.split("\n").find{|line|line.include?("sysname ")}.to_s.split("sysname ")[1]
|
@@ -348,7 +368,11 @@ module NE40E_X8
|
|
348
368
|
begin
|
349
369
|
raw.split("\n")
|
350
370
|
rescue
|
351
|
-
|
371
|
+
begin
|
372
|
+
raw = braw.force_encoding('GBK').encode('UTF-8')
|
373
|
+
rescue
|
374
|
+
raw = braw.force_encoding('ASCII-8BIT')
|
375
|
+
end
|
352
376
|
end
|
353
377
|
cfg = {}
|
354
378
|
hostname = guards[0] || raw.split("\n").find{|line|line.include?("sysname ")}.to_s.split("sysname ")[1]
|
@@ -383,7 +407,11 @@ module NE40E_X16
|
|
383
407
|
begin
|
384
408
|
raw.split("\n")
|
385
409
|
rescue
|
386
|
-
|
410
|
+
begin
|
411
|
+
raw = braw.force_encoding('GBK').encode('UTF-8')
|
412
|
+
rescue
|
413
|
+
raw = braw.force_encoding('ASCII-8BIT')
|
414
|
+
end
|
387
415
|
end
|
388
416
|
cfg = {}
|
389
417
|
hostname = guards[0] || raw.split("\n").find{|line|line.include?("sysname ")}.to_s.split("sysname ")[1]
|
@@ -420,7 +448,11 @@ module NE40E_X16A
|
|
420
448
|
begin
|
421
449
|
raw.split("\n")
|
422
450
|
rescue
|
423
|
-
|
451
|
+
begin
|
452
|
+
raw = braw.force_encoding('GBK').encode('UTF-8')
|
453
|
+
rescue
|
454
|
+
raw = braw.force_encoding('ASCII-8BIT')
|
455
|
+
end
|
424
456
|
end
|
425
457
|
cfg = {}
|
426
458
|
hostname = guards[0] || raw.split("\n").find{|line|line.include?("sysname ")}.to_s.split("sysname ")[1]
|
@@ -456,7 +488,11 @@ module NE5000E_X16
|
|
456
488
|
begin
|
457
489
|
raw.split("\n")
|
458
490
|
rescue
|
459
|
-
|
491
|
+
begin
|
492
|
+
raw = braw.force_encoding('GBK').encode('UTF-8')
|
493
|
+
rescue
|
494
|
+
raw = braw.force_encoding('ASCII-8BIT')
|
495
|
+
end
|
460
496
|
end
|
461
497
|
cfg = {}
|
462
498
|
hostname = guards[0] || raw.split("\n").find{|line|line.include?("sysname ")}.to_s.split("sysname ")[1]
|
@@ -492,7 +528,11 @@ module NE5000E_X16A
|
|
492
528
|
begin
|
493
529
|
raw.split("\n")
|
494
530
|
rescue
|
495
|
-
|
531
|
+
begin
|
532
|
+
raw = braw.force_encoding('GBK').encode('UTF-8')
|
533
|
+
rescue
|
534
|
+
raw = braw.force_encoding('ASCII-8BIT')
|
535
|
+
end
|
496
536
|
end
|
497
537
|
cfg = {}
|
498
538
|
hostname = guards[0] || raw.split("\n").find{|line|line.include?("sysname ")}.to_s.split("sysname ")[1]
|
@@ -527,7 +567,11 @@ module NE5000E_20
|
|
527
567
|
begin
|
528
568
|
raw.split("\n")
|
529
569
|
rescue
|
530
|
-
|
570
|
+
begin
|
571
|
+
raw = braw.force_encoding('GBK').encode('UTF-8')
|
572
|
+
rescue
|
573
|
+
raw = braw.force_encoding('ASCII-8BIT')
|
574
|
+
end
|
531
575
|
end
|
532
576
|
cfg = {}
|
533
577
|
hostname = guards[0] || raw.split("\n").find{|line|line.include?("sysname ")}.to_s.split("sysname ")[1]
|
@@ -567,7 +611,11 @@ module NE8000E_X8
|
|
567
611
|
begin
|
568
612
|
raw.split("\n")
|
569
613
|
rescue
|
570
|
-
|
614
|
+
begin
|
615
|
+
raw = braw.force_encoding('GBK').encode('UTF-8')
|
616
|
+
rescue
|
617
|
+
raw = braw.force_encoding('ASCII-8BIT')
|
618
|
+
end
|
571
619
|
end
|
572
620
|
cfg = {}
|
573
621
|
hostname = guards[0] || raw.split("\n").find{|line|line.include?("sysname ")}.to_s.split("sysname ")[1]
|
@@ -602,7 +650,11 @@ module NE8100_X8
|
|
602
650
|
begin
|
603
651
|
raw.split("\n")
|
604
652
|
rescue
|
605
|
-
|
653
|
+
begin
|
654
|
+
raw = braw.force_encoding('GBK').encode('UTF-8')
|
655
|
+
rescue
|
656
|
+
raw = braw.force_encoding('ASCII-8BIT')
|
657
|
+
end
|
606
658
|
end
|
607
659
|
cfg = {}
|
608
660
|
hostname = guards[0] || raw.split("\n").find{|line|line.include?("sysname ")}.to_s.split("sysname ")[1]
|
@@ -638,7 +690,11 @@ module VNE9000
|
|
638
690
|
begin
|
639
691
|
raw.split("\n")
|
640
692
|
rescue
|
641
|
-
|
693
|
+
begin
|
694
|
+
raw = braw.force_encoding('GBK').encode('UTF-8')
|
695
|
+
rescue
|
696
|
+
raw = braw.force_encoding('ASCII-8BIT')
|
697
|
+
end
|
642
698
|
end
|
643
699
|
cfg = {}
|
644
700
|
hostname = guards[0] || raw.split("\n").find{|line|line.include?("sysname ")}.to_s.split("sysname ")[1]
|
data/network.rb
CHANGED
data/utility/ipv4_address.rb
CHANGED
@@ -82,14 +82,41 @@ class IPv4
|
|
82
82
|
|
83
83
|
def + num
|
84
84
|
@number += num
|
85
|
-
generate("0b"+("%032b"
|
85
|
+
generate("0b"+("%032b" % @number).unpack("a8a8a8a8").join("."))
|
86
86
|
end
|
87
87
|
|
88
88
|
def - num
|
89
89
|
@number -= num
|
90
|
-
generate("0b"+("%032b"
|
90
|
+
generate("0b"+("%032b" % @number).unpack("a8a8a8a8").join("."))
|
91
|
+
end
|
92
|
+
|
93
|
+
def & another
|
94
|
+
target = nil
|
95
|
+
target = another if another.is_a?(IPv4)
|
96
|
+
target = IPv4Mask.number(another) if another.is_a?(Integer)
|
97
|
+
return self unless target
|
98
|
+
newaddr = []
|
99
|
+
self.numbers.each_with_index do|number, index|
|
100
|
+
newaddr << (number & target.numbers[index])
|
101
|
+
end
|
102
|
+
return IP.v4(newaddr.join('.'))
|
91
103
|
end
|
92
104
|
|
105
|
+
def delegation base_pref, sub_pref
|
106
|
+
base_len = base_pref.is_a?(IPv4) ? base_pref.mask_counter : base_pref.is_a?(Integer) ? base_pref : nil
|
107
|
+
sub_len = sub_pref.is_a?(IPv4) ? sub_pref.mask_counter : sub_pref.is_a?(Integer) ? sub_pref : nil
|
108
|
+
return [] unless base_len && sub_len
|
109
|
+
return [] unless base_len < sub_len
|
110
|
+
return [] unless base_len <= 32 && sub_len <= 32
|
111
|
+
base = self & base_len
|
112
|
+
pref = IPv4Mask.number sub_len
|
113
|
+
return (0..(2**(sub_len - base_len)-1)).to_a.map do|i|
|
114
|
+
new_subnet = base.clone
|
115
|
+
new_subnet + (i << (32-sub_len))
|
116
|
+
[new_subnet, pref]
|
117
|
+
end
|
118
|
+
end
|
119
|
+
|
93
120
|
def is_class_a?
|
94
121
|
first =IPv4.new('10.0.0.0').number
|
95
122
|
last = IPv4.new('126.255.255.255').number
|
data/utility/ipv6_address.rb
CHANGED
@@ -61,14 +61,42 @@ class IPv6
|
|
61
61
|
|
62
62
|
def + num
|
63
63
|
@number += num
|
64
|
-
generate(("%032x"
|
64
|
+
generate(("%032x" % @number).unpack("a4a4a4a4a4a4a4a4").join(":"))
|
65
65
|
end
|
66
66
|
|
67
67
|
def - num
|
68
68
|
@number -= num
|
69
|
-
generate(("%032x"
|
69
|
+
generate(("%032x" % @number).unpack("a4a4a4a4a4a4a4a4").join(":"))
|
70
70
|
end
|
71
|
-
|
71
|
+
|
72
|
+
def & another
|
73
|
+
target = nil
|
74
|
+
target = another if another.is_a?(IPv6)
|
75
|
+
target = IPv6Mask.number(another) if another.is_a?(Integer)
|
76
|
+
return self unless target
|
77
|
+
newaddr = []
|
78
|
+
self.numbers.each_with_index do|number, index|
|
79
|
+
newaddr << "%04x"%(number & target.numbers[index])
|
80
|
+
end
|
81
|
+
result = IP.v6(newaddr.join(':'))
|
82
|
+
return result
|
83
|
+
end
|
84
|
+
|
85
|
+
def delegation base_pref, sub_pref
|
86
|
+
base_len = base_pref.is_a?(IPv6) ? base_pref.mask_counter : base_pref.is_a?(Integer) ? base_pref : nil
|
87
|
+
sub_len = sub_pref.is_a?(IPv6) ? sub_pref.mask_counter : sub_pref.is_a?(Integer) ? sub_pref : nil
|
88
|
+
return [] unless base_len && sub_len
|
89
|
+
return [] unless base_len < sub_len
|
90
|
+
return [] unless base_len <= 128 && sub_len <= 128
|
91
|
+
base = self & base_len
|
92
|
+
pref = IPv6Mask.number sub_len
|
93
|
+
return (0..(2**(sub_len - base_len)-1)).to_a.map do|i|
|
94
|
+
new_subnet = base.clone
|
95
|
+
new_subnet + (i << (128-sub_len))
|
96
|
+
[new_subnet, pref]
|
97
|
+
end
|
98
|
+
end
|
99
|
+
|
72
100
|
#### mask ####
|
73
101
|
def mask_counter
|
74
102
|
if is_mask?
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: network-utility
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.1.
|
4
|
+
version: 1.1.23
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Matt
|
@@ -242,7 +242,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
242
242
|
- !ruby/object:Gem::Version
|
243
243
|
version: '0'
|
244
244
|
requirements: []
|
245
|
-
rubygems_version: 3.6.
|
245
|
+
rubygems_version: 3.6.9
|
246
246
|
specification_version: 4
|
247
247
|
summary: core
|
248
248
|
test_files: []
|