netaddr 1.5.3 → 2.0.6
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/LICENSE +201 -0
- data/README.md +28 -8
- data/lib/eui48.rb +65 -0
- data/lib/eui64.rb +77 -0
- data/lib/ipv4.rb +87 -0
- data/lib/ipv4net.rb +262 -0
- data/lib/ipv6.rb +146 -0
- data/lib/ipv6net.rb +267 -0
- data/lib/mask128.rb +70 -0
- data/lib/mask32.rb +105 -0
- data/lib/netaddr.rb +122 -20
- data/lib/util.rb +373 -0
- data/test/eui48_test.rb +30 -0
- data/test/eui64_test.rb +32 -0
- data/test/examples.rb +155 -0
- data/test/ipv4_test.rb +60 -0
- data/test/ipv4net_test.rb +206 -0
- data/test/ipv6_test.rb +135 -0
- data/test/ipv6net_test.rb +199 -0
- data/test/mask128_test.rb +45 -0
- data/test/mask32_test.rb +56 -0
- data/test/netaddr_test.rb +149 -0
- data/test/run_all.rb +10 -0
- metadata +25 -20
- data/Errors +0 -7
- data/changelog +0 -52
- data/lib/cidr.rb +0 -2014
- data/lib/cidr_shortcuts.rb +0 -401
- data/lib/eui.rb +0 -402
- data/lib/ip_math.rb +0 -227
- data/lib/methods.rb +0 -1013
- data/lib/tree.rb +0 -816
- data/lib/validation_shortcuts.rb +0 -201
- data/license +0 -13
- data/test/cidr_test.rb +0 -545
- data/test/eui_test.rb +0 -101
- data/test/methods_test.rb +0 -331
- data/test/tree_test.rb +0 -347
@@ -0,0 +1,199 @@
|
|
1
|
+
#!/usr/bin/ruby
|
2
|
+
|
3
|
+
require_relative "../lib/netaddr.rb"
|
4
|
+
require 'test/unit'
|
5
|
+
|
6
|
+
class TestIPv6Net < Test::Unit::TestCase
|
7
|
+
def test_new
|
8
|
+
ip = NetAddr::IPv6.parse("1::")
|
9
|
+
m128 = NetAddr::Mask128.new(24)
|
10
|
+
net = NetAddr::IPv6Net.new(ip,m128)
|
11
|
+
assert_equal("1::/24", net.to_s)
|
12
|
+
|
13
|
+
assert_equal("1::/64", NetAddr::IPv6Net.new(ip,nil).to_s)
|
14
|
+
|
15
|
+
ip = NetAddr::IPv6.parse("::")
|
16
|
+
assert_equal("::/128", NetAddr::IPv6Net.new(ip,nil).to_s)
|
17
|
+
end
|
18
|
+
|
19
|
+
def test_parse
|
20
|
+
assert_equal("1::/24", NetAddr::IPv6Net.parse("1::1/24").to_s)
|
21
|
+
assert_equal("::/128", NetAddr::IPv6Net.parse("::").to_s) # default /128
|
22
|
+
assert_equal("1::/64", NetAddr::IPv6Net.parse("1::1").to_s) # default /64
|
23
|
+
end
|
24
|
+
|
25
|
+
def test_cmp
|
26
|
+
net1 = NetAddr::IPv6Net.parse("1:1::/32")
|
27
|
+
net2 = NetAddr::IPv6Net.parse("1::/32")
|
28
|
+
net3 =NetAddr::IPv6Net.parse("1:2::/32")
|
29
|
+
net4 = NetAddr::IPv6Net.parse("1:1::/33")
|
30
|
+
net5 = NetAddr::IPv6Net.parse("1:1::/32")
|
31
|
+
|
32
|
+
assert_equal(1, net1.cmp(net2)) # ip less
|
33
|
+
assert_equal(-1, net1.cmp(net3))# ip greater
|
34
|
+
assert_equal(-1, net4.cmp(net1)) # ip eq, mask less
|
35
|
+
assert_equal(1, net1.cmp(net4)) # ip eq, mask greater
|
36
|
+
assert_equal(0, net1.cmp(net5)) # eq
|
37
|
+
end
|
38
|
+
|
39
|
+
def test_contains
|
40
|
+
net = NetAddr::IPv6Net.parse("1:8::/29")
|
41
|
+
ip1 = NetAddr::IPv6.parse("1:f::")
|
42
|
+
ip2 = NetAddr::IPv6.parse("1:10::")
|
43
|
+
ip3 = NetAddr::IPv6.parse("1:7::")
|
44
|
+
|
45
|
+
assert_equal(true, net.contains(ip1))
|
46
|
+
assert_equal(false, net.contains(ip2))
|
47
|
+
assert_equal(false, net.contains(ip3))
|
48
|
+
end
|
49
|
+
|
50
|
+
def test_fill
|
51
|
+
# filter supernet. remove subnets of subnets. basic fwd fill.
|
52
|
+
parent = NetAddr::IPv6Net.parse("ff00::/8")
|
53
|
+
nets = []
|
54
|
+
["ff00::/8", "ff00::/9", "ff08::/14", "fe00::/7", "ff20::/11", "ff20::/12"].each do |net|
|
55
|
+
nets.push(NetAddr::IPv6Net.parse(net))
|
56
|
+
end
|
57
|
+
expect = ["ff00::/9", "ff80::/9"]
|
58
|
+
i = 0
|
59
|
+
parent.fill(nets).each do |net|
|
60
|
+
assert_equal(expect[i],net.to_s)
|
61
|
+
i += 1
|
62
|
+
end
|
63
|
+
|
64
|
+
# basic backfill
|
65
|
+
parent = NetAddr::IPv6Net.parse("8000::/1")
|
66
|
+
nets = []
|
67
|
+
["c000::/2"].each do |net|
|
68
|
+
nets.push(NetAddr::IPv6Net.parse(net))
|
69
|
+
end
|
70
|
+
expect = ["8000::/2","c000::/2"]
|
71
|
+
i = 0
|
72
|
+
parent.fill(nets).each do |net|
|
73
|
+
assert_equal(expect[i],net.to_s)
|
74
|
+
i += 1
|
75
|
+
end
|
76
|
+
|
77
|
+
# basic fwd fill with non-contiguous subnets
|
78
|
+
parent = NetAddr::IPv6Net.parse("ff00::/121")
|
79
|
+
nets = []
|
80
|
+
["ff00::/126", "ff00::/120"].each do |net|
|
81
|
+
nets.push(NetAddr::IPv6Net.parse(net))
|
82
|
+
end
|
83
|
+
expect = ["ff00::/126", "ff00::4/126", "ff00::8/125", "ff00::10/124", "ff00::20/123", "ff00::40/122"]
|
84
|
+
i = 0
|
85
|
+
parent.fill(nets).each do |net|
|
86
|
+
assert_equal(expect[i],net.to_s)
|
87
|
+
i += 1
|
88
|
+
end
|
89
|
+
|
90
|
+
# basic backfill. complex fwd fill that uses 'shrink' of the proposed ffff:ffff:ffff:fff8::/62 subnet. designed to cross the /64 bit boundary.
|
91
|
+
parent = NetAddr::IPv6Net.parse("fff:ffff:ffff:fff0::/60")
|
92
|
+
nets = []
|
93
|
+
["ffff:ffff:ffff:fff4::/62", "ffff:ffff:ffff:fffb::/65"].each do |net|
|
94
|
+
nets.push(NetAddr::IPv6Net.parse(net))
|
95
|
+
end
|
96
|
+
expect = ["ffff:ffff:ffff:fff0::/62", "ffff:ffff:ffff:fff4::/62", "ffff:ffff:ffff:fff8::/63", "ffff:ffff:ffff:fffa::/64", "ffff:ffff:ffff:fffb::/65",
|
97
|
+
"ffff:ffff:ffff:fffb:8000::/65", "ffff:ffff:ffff:fffc::/62"]
|
98
|
+
i = 0
|
99
|
+
parent.fill(nets).each do |net|
|
100
|
+
assert_equal(expect[i],net.to_s)
|
101
|
+
i += 1
|
102
|
+
end
|
103
|
+
|
104
|
+
# list contains the supernet
|
105
|
+
parent = NetAddr::IPv6Net.parse("ffff::/16")
|
106
|
+
nets = []
|
107
|
+
["ffff::/16"].each do |net|
|
108
|
+
nets.push(NetAddr::IPv6Net.parse(net))
|
109
|
+
end
|
110
|
+
expect = []
|
111
|
+
i = 0
|
112
|
+
parent.fill(nets).each do |net|
|
113
|
+
assert_equal(expect[i],net.to_s)
|
114
|
+
i += 1
|
115
|
+
end
|
116
|
+
end
|
117
|
+
|
118
|
+
def test_next
|
119
|
+
assert_equal("::2/127", NetAddr::IPv6Net.parse("::/127").next.to_s)
|
120
|
+
assert_equal("::8/125", NetAddr::IPv6Net.parse("::4/126").next.to_s)
|
121
|
+
assert_equal("0:0:0:2::/63", NetAddr::IPv6Net.parse("::1:8000:0:0:0/65").next.to_s)
|
122
|
+
assert_equal("0:0:0:3::/64", NetAddr::IPv6Net.parse("::2:8000:0:0:0/65").next.to_s)
|
123
|
+
assert_nil(NetAddr::IPv6Net.parse("ffff::/16").next)
|
124
|
+
end
|
125
|
+
|
126
|
+
def test_next_sib
|
127
|
+
assert_equal("0:0:0:2::/65", NetAddr::IPv6Net.parse("::1:8000:0:0:0/65",).next_sib.to_s)
|
128
|
+
assert_equal("0:0:0:2::/64", NetAddr::IPv6Net.parse("0:0:0:1::/64",).next_sib.to_s)
|
129
|
+
assert_equal("2::/16", NetAddr::IPv6Net.parse("1::/16").next_sib.to_s)
|
130
|
+
assert_nil(NetAddr::IPv6Net.parse("ffff::/16").next_sib)
|
131
|
+
end
|
132
|
+
|
133
|
+
def test_nth
|
134
|
+
assert_equal("1::", NetAddr::IPv6Net.parse("1::0/64").nth(0).to_s)
|
135
|
+
assert_equal("::", NetAddr::IPv6Net.parse("::/127").nth(0).to_s)
|
136
|
+
assert_equal("::1", NetAddr::IPv6Net.parse("::/127").nth(1).to_s)
|
137
|
+
assert_nil(NetAddr::IPv6Net.parse("::/127").nth(2))
|
138
|
+
end
|
139
|
+
|
140
|
+
def test_nth_subnet
|
141
|
+
assert_equal("1::/30", NetAddr::IPv6Net.parse("1::/24").nth_subnet(30,0).to_s)
|
142
|
+
assert_nil(NetAddr::IPv6Net.parse("1::").nth_subnet(26,4))
|
143
|
+
end
|
144
|
+
|
145
|
+
def test_prev
|
146
|
+
assert_equal("1::/125", NetAddr::IPv6Net.parse("1::8/126").prev.to_s)
|
147
|
+
assert_equal("f::/63", NetAddr::IPv6Net.parse("f:0:0:2::/63").prev.to_s)
|
148
|
+
assert_equal("e::/16", NetAddr::IPv6Net.parse("f::/63").prev.to_s)
|
149
|
+
assert_nil(NetAddr::IPv6Net.parse("::").prev)
|
150
|
+
end
|
151
|
+
|
152
|
+
def test_prev_sib
|
153
|
+
assert_equal("0:0:0:1::/64", NetAddr::IPv6Net.parse("0:0:0:2::/64").prev_sib.to_s)
|
154
|
+
assert_equal("1::/16", NetAddr::IPv6Net.parse("2::/16").prev_sib.to_s)
|
155
|
+
assert_nil(NetAddr::IPv6Net.parse("::/64").prev_sib)
|
156
|
+
end
|
157
|
+
|
158
|
+
def test_rel
|
159
|
+
net1 = NetAddr::IPv6Net.parse("1::/63")
|
160
|
+
net2 = NetAddr::IPv6Net.parse("1::/64")
|
161
|
+
net3 = NetAddr::IPv6Net.parse("1::/60")
|
162
|
+
net4 = NetAddr::IPv6Net.parse("1:0:0:1::/64")
|
163
|
+
net5 = NetAddr::IPv6Net.parse("2::/64")
|
164
|
+
assert_equal(1, net1.rel(net2)) # net eq, supernet
|
165
|
+
assert_equal(-1, net2.rel(net1)) # net eq, subnet
|
166
|
+
assert_equal(0, net2.rel(net2)) # eq
|
167
|
+
assert_equal(1, net3.rel(net4)) # net ne, supernet
|
168
|
+
assert_equal(-1, net4.rel(net3)) # net ne, subnet
|
169
|
+
assert_nil(net2.rel(net5)) # unrelated
|
170
|
+
end
|
171
|
+
|
172
|
+
def test_resize
|
173
|
+
assert_equal("1::/64", NetAddr::IPv6Net.parse("1::/63").resize(64).to_s)
|
174
|
+
end
|
175
|
+
|
176
|
+
def test_subnet_count
|
177
|
+
assert_equal(2, NetAddr::IPv6Net.parse("ff::/8").subnet_count(9))
|
178
|
+
assert_equal(4, NetAddr::IPv6Net.parse("ff::/8").subnet_count(10))
|
179
|
+
assert_equal(0, NetAddr::IPv6Net.parse("ff::/8").subnet_count(8))
|
180
|
+
assert_equal(0, NetAddr::IPv6Net.parse("::/0").subnet_count(128))
|
181
|
+
end
|
182
|
+
|
183
|
+
def test_summ
|
184
|
+
net1 = NetAddr::IPv6Net.parse("1::/128")
|
185
|
+
net2 = NetAddr::IPv6Net.parse("1::1/128")
|
186
|
+
net3 = NetAddr::IPv6Net.parse("1::0/128")
|
187
|
+
net4 = NetAddr::IPv6Net.parse("1::/16")
|
188
|
+
net5 = NetAddr::IPv6Net.parse("2::/16")
|
189
|
+
net6 = NetAddr::IPv6Net.parse("10::/12")
|
190
|
+
net7 = NetAddr::IPv6Net.parse("20::/12")
|
191
|
+
net8 = NetAddr::IPv6Net.parse("8::/17")
|
192
|
+
assert_equal("1::/127", net1.summ(net2).to_s) # lesser to greater
|
193
|
+
assert_equal("1::/127", net2.summ(net3).to_s) # greater to lesser
|
194
|
+
assert_nil(net4.summ(net5)) # different nets
|
195
|
+
assert_nil(net6.summ(net7)) # consecutive but not within bit boundary
|
196
|
+
assert_nil(net4.summ(net8)) # within bit boundary, but not same size
|
197
|
+
end
|
198
|
+
|
199
|
+
end
|
@@ -0,0 +1,45 @@
|
|
1
|
+
#!/usr/bin/ruby
|
2
|
+
|
3
|
+
require_relative "../lib/netaddr.rb"
|
4
|
+
require 'test/unit'
|
5
|
+
|
6
|
+
class TestMask128 < Test::Unit::TestCase
|
7
|
+
def test_new
|
8
|
+
m128 = NetAddr::Mask128.new(24)
|
9
|
+
assert_equal("/24", m128.to_s)
|
10
|
+
assert_equal(0xffffff00000000000000000000000000, m128.mask)
|
11
|
+
|
12
|
+
assert_raise(NetAddr::ValidationError){ NetAddr::Mask128.new(-1) }
|
13
|
+
assert_raise(NetAddr::ValidationError){ NetAddr::Mask128.new(129) }
|
14
|
+
assert_raise(NetAddr::ValidationError){ NetAddr::Mask128.new("/24") }
|
15
|
+
end
|
16
|
+
|
17
|
+
def test_parse
|
18
|
+
m128 = NetAddr::Mask128.parse("/24")
|
19
|
+
assert_equal("/24", m128.to_s)
|
20
|
+
|
21
|
+
m128 = NetAddr::Mask128.parse("24")
|
22
|
+
assert_equal("/24", m128.to_s)
|
23
|
+
|
24
|
+
assert_raise(NetAddr::ValidationError){ NetAddr::Mask128.parse("/129") }
|
25
|
+
end
|
26
|
+
|
27
|
+
def test_cmp
|
28
|
+
m = NetAddr::Mask128.new(24)
|
29
|
+
m2 = NetAddr::Mask128.new(25)
|
30
|
+
m3 = NetAddr::Mask128.new(23)
|
31
|
+
m4 = NetAddr::Mask128.new(24)
|
32
|
+
assert_equal(1, m.cmp(m2))
|
33
|
+
assert_equal(-1, m.cmp(m3))
|
34
|
+
assert_equal(0, m.cmp(m4))
|
35
|
+
end
|
36
|
+
|
37
|
+
def test_len
|
38
|
+
m = NetAddr::Mask128.new(65)
|
39
|
+
assert_equal(2**(128-65), m.len())
|
40
|
+
|
41
|
+
m = NetAddr::Mask128.new(64)
|
42
|
+
assert_equal(0, m.len())
|
43
|
+
end
|
44
|
+
|
45
|
+
end
|
data/test/mask32_test.rb
ADDED
@@ -0,0 +1,56 @@
|
|
1
|
+
#!/usr/bin/ruby
|
2
|
+
|
3
|
+
require_relative "../lib/netaddr.rb"
|
4
|
+
require 'test/unit'
|
5
|
+
|
6
|
+
class TestMask32 < Test::Unit::TestCase
|
7
|
+
def test_new
|
8
|
+
m32 = NetAddr::Mask32.new(24)
|
9
|
+
assert_equal("/24", m32.to_s)
|
10
|
+
assert_equal(0xffffff00, m32.mask)
|
11
|
+
|
12
|
+
assert_raise(NetAddr::ValidationError){ NetAddr::Mask32.new(-1) }
|
13
|
+
assert_raise(NetAddr::ValidationError){ NetAddr::Mask32.new(33) }
|
14
|
+
assert_raise(NetAddr::ValidationError){ NetAddr::Mask32.new("/24") }
|
15
|
+
end
|
16
|
+
|
17
|
+
def test_parse
|
18
|
+
m32 = NetAddr::Mask32.parse("255.255.255.0")
|
19
|
+
assert_equal("/24", m32.to_s)
|
20
|
+
|
21
|
+
m32 = NetAddr::Mask32.parse("/24")
|
22
|
+
assert_equal("/24", m32.to_s)
|
23
|
+
|
24
|
+
assert_raise(NetAddr::ValidationError){ NetAddr::Mask32.parse("255.248.255.0") }
|
25
|
+
end
|
26
|
+
|
27
|
+
def test_cmp
|
28
|
+
m = NetAddr::Mask32.new(24)
|
29
|
+
m2 = NetAddr::Mask32.new(25)
|
30
|
+
m3 = NetAddr::Mask32.new(23)
|
31
|
+
m4 = NetAddr::Mask32.new(24)
|
32
|
+
assert_equal(1, m.cmp(m2))
|
33
|
+
assert_equal(-1, m.cmp(m3))
|
34
|
+
assert_equal(0, m.cmp(m4))
|
35
|
+
end
|
36
|
+
|
37
|
+
def test_extended
|
38
|
+
m32 = NetAddr::Mask32.new(24)
|
39
|
+
assert_equal("255.255.255.0", m32.extended)
|
40
|
+
end
|
41
|
+
|
42
|
+
def test_len
|
43
|
+
m = NetAddr::Mask32.new(24)
|
44
|
+
assert_equal(256, m.len())
|
45
|
+
|
46
|
+
m = NetAddr::Mask32.new(26)
|
47
|
+
assert_equal(64, m.len())
|
48
|
+
|
49
|
+
m = NetAddr::Mask32.new(32)
|
50
|
+
assert_equal(1, m.len())
|
51
|
+
|
52
|
+
m = NetAddr::Mask32.new(0)
|
53
|
+
assert_equal(0, m.len())
|
54
|
+
end
|
55
|
+
|
56
|
+
end
|
@@ -0,0 +1,149 @@
|
|
1
|
+
#!/usr/bin/ruby
|
2
|
+
|
3
|
+
require_relative "../lib/netaddr.rb"
|
4
|
+
require 'test/unit'
|
5
|
+
|
6
|
+
class TestNetAddr < Test::Unit::TestCase
|
7
|
+
|
8
|
+
def test_parse_ip
|
9
|
+
assert_equal("128.0.0.1", NetAddr.parse_ip("128.0.0.1").to_s)
|
10
|
+
assert_equal("1::1", NetAddr.parse_ip("1::1").to_s)
|
11
|
+
end
|
12
|
+
|
13
|
+
def test_parse_net
|
14
|
+
assert_equal("128.0.0.1/32", NetAddr.parse_net("128.0.0.1/32").to_s)
|
15
|
+
assert_equal("1::/24", NetAddr.parse_net("1::1/24").to_s)
|
16
|
+
assert_equal("::ffff:aabb:ccdd/128", NetAddr.parse_net("::ffff:170.187.204.221/128").to_s)
|
17
|
+
end
|
18
|
+
|
19
|
+
def test_ipv4_prefix_len
|
20
|
+
assert_equal(32,NetAddr.ipv4_prefix_len(1))
|
21
|
+
assert_equal(27,NetAddr.ipv4_prefix_len(30))
|
22
|
+
assert_equal(24,NetAddr.ipv4_prefix_len(254))
|
23
|
+
assert_equal(16,NetAddr.ipv4_prefix_len(0xfffe))
|
24
|
+
assert_equal(8,NetAddr.ipv4_prefix_len(0xfffffe))
|
25
|
+
assert_equal(0,NetAddr.ipv4_prefix_len(0xffffffff))
|
26
|
+
end
|
27
|
+
|
28
|
+
def test_sort_IPv4
|
29
|
+
ips = []
|
30
|
+
["10.0.0.0","1.1.1.1","0.0.0.0","10.1.10.1"].each do |net|
|
31
|
+
ips.push(NetAddr::IPv4.parse(net))
|
32
|
+
end
|
33
|
+
sorted = NetAddr.sort_IPv4(ips)
|
34
|
+
expect = [ips[2],ips[1],ips[0],ips[3]]
|
35
|
+
assert_equal(expect, sorted)
|
36
|
+
end
|
37
|
+
|
38
|
+
def test_sort_IPv4Net
|
39
|
+
nets = []
|
40
|
+
["10.0.0.0/24", "1.0.0.0/24", "10.0.0.0/8", "192.168.1.0/26", "8.8.8.8/32"].each do |net|
|
41
|
+
nets.push(NetAddr::IPv4Net.parse(net))
|
42
|
+
end
|
43
|
+
sorted = NetAddr.sort_IPv4Net(nets)
|
44
|
+
expect = [nets[1],nets[4],nets[0],nets[2],nets[3]]
|
45
|
+
assert_equal(expect, sorted)
|
46
|
+
end
|
47
|
+
|
48
|
+
def test_summ_IPv4Net
|
49
|
+
nets = []
|
50
|
+
["10.0.0.0/29", "10.0.0.8/30", "10.0.0.12/30", "10.0.0.16/28", "10.0.0.32/27", "10.0.0.64/26", "10.0.0.128/25"].each do |net|
|
51
|
+
nets.push(NetAddr::IPv4Net.parse(net))
|
52
|
+
end
|
53
|
+
expect = ["10.0.0.0/24"]
|
54
|
+
i = 0
|
55
|
+
NetAddr.summ_IPv4Net(nets).each do |net|
|
56
|
+
assert_equal(expect[i],net.to_s)
|
57
|
+
i += 1
|
58
|
+
end
|
59
|
+
|
60
|
+
nets = []
|
61
|
+
["10.0.0.0/24", "1.0.0.0/8", "3.4.5.6/32", "3.4.5.8/31", "0.0.0.0/0"].each do |net|
|
62
|
+
nets.push(NetAddr::IPv4Net.parse(net))
|
63
|
+
end
|
64
|
+
expect = ["0.0.0.0/0"]
|
65
|
+
i = 0
|
66
|
+
NetAddr.summ_IPv4Net(nets).each do |net|
|
67
|
+
assert_equal(expect[i],net.to_s)
|
68
|
+
i += 1
|
69
|
+
end
|
70
|
+
|
71
|
+
nets = []
|
72
|
+
["10.0.1.0/25", "10.0.1.0/26", "10.0.0.16/28", "10.0.0.32/27", "10.0.0.128/26", "10.0.0.192/26", "10.0.0.32/27"].each do |net|
|
73
|
+
nets.push(NetAddr::IPv4Net.parse(net))
|
74
|
+
end
|
75
|
+
expect = ["10.0.0.16/28", "10.0.0.32/27", "10.0.0.128/25", "10.0.1.0/25"]
|
76
|
+
i = 0
|
77
|
+
NetAddr.summ_IPv4Net(nets).each do |net|
|
78
|
+
assert_equal(expect[i],net.to_s)
|
79
|
+
i += 1
|
80
|
+
end
|
81
|
+
|
82
|
+
nets = []
|
83
|
+
["10.0.0.0/26","10.0.0.64/26","10.0.0.0/24","10.0.0.192/26","10.0.0.128/26"].each do |net| # test out of order
|
84
|
+
nets.push(NetAddr::IPv4Net.parse(net))
|
85
|
+
end
|
86
|
+
expect = ["10.0.0.0/24"]
|
87
|
+
i = 0
|
88
|
+
NetAddr.summ_IPv4Net(nets).each do |net|
|
89
|
+
assert_equal(expect[i],net.to_s)
|
90
|
+
i += 1
|
91
|
+
end
|
92
|
+
end
|
93
|
+
|
94
|
+
def test_sort_IPv6
|
95
|
+
ips = []
|
96
|
+
["1::", "3::", "2::", "::", "::1"].each do |net|
|
97
|
+
ips.push(NetAddr::IPv6.parse(net))
|
98
|
+
end
|
99
|
+
sorted = NetAddr.sort_IPv6(ips)
|
100
|
+
expect = [ips[3],ips[4],ips[0],ips[2],ips[1]]
|
101
|
+
assert_equal(expect, sorted)
|
102
|
+
end
|
103
|
+
|
104
|
+
def test_sort_IPv6Net
|
105
|
+
nets = []
|
106
|
+
["1::/64", "2::/64", "1::/16", "::", "::1"].each do |net|
|
107
|
+
nets.push(NetAddr::IPv6Net.parse(net))
|
108
|
+
end
|
109
|
+
sorted = NetAddr.sort_IPv6Net(nets)
|
110
|
+
expect = [nets[3],nets[4],nets[0],nets[2],nets[1]] # ::/128 ::1/128 1::/64 1::/16 2::/64
|
111
|
+
assert_equal(expect, sorted)
|
112
|
+
end
|
113
|
+
|
114
|
+
def test_summ_IPv6Net
|
115
|
+
nets = []
|
116
|
+
["ff00::/13", "ff08::/14", "ff0c::/14", "ff10::/12", "ff20::/11", "ff40::/10", "ff80::/9"].each do |net|
|
117
|
+
nets.push(NetAddr::IPv6Net.parse(net))
|
118
|
+
end
|
119
|
+
expect = ["ff00::/8"]
|
120
|
+
i = 0
|
121
|
+
NetAddr.summ_IPv6Net(nets).each do |net|
|
122
|
+
assert_equal(expect[i],net.to_s)
|
123
|
+
i += 1
|
124
|
+
end
|
125
|
+
|
126
|
+
nets = []
|
127
|
+
["2::/32", "::1", "fec0::/16", "1::/16", "::/0"].each do |net|
|
128
|
+
nets.push(NetAddr::IPv6Net.parse(net))
|
129
|
+
end
|
130
|
+
expect = ["::/0"]
|
131
|
+
i = 0
|
132
|
+
NetAddr.summ_IPv6Net(nets).each do |net|
|
133
|
+
assert_equal(expect[i],net.to_s)
|
134
|
+
i += 1
|
135
|
+
end
|
136
|
+
|
137
|
+
nets = []
|
138
|
+
["ff80::/9", "ff10::/12", "ff80::/10", "ff20::/12", "fff0::/16", "fff1::/16", "ff80::/10"].each do |net|
|
139
|
+
nets.push(NetAddr::IPv6Net.parse(net))
|
140
|
+
end
|
141
|
+
expect = ["ff10::/12", "ff20::/12", "ff80::/9", "fff0::/15"]
|
142
|
+
i = 0
|
143
|
+
NetAddr.summ_IPv6Net(nets).each do |net|
|
144
|
+
assert_equal(expect[i],net.to_s)
|
145
|
+
i += 1
|
146
|
+
end
|
147
|
+
end
|
148
|
+
|
149
|
+
end
|
data/test/run_all.rb
ADDED
@@ -0,0 +1,10 @@
|
|
1
|
+
require_relative "examples.rb"
|
2
|
+
require_relative "netaddr_test.rb"
|
3
|
+
require_relative "eui48_test.rb"
|
4
|
+
require_relative "eui64_test.rb"
|
5
|
+
require_relative "ipv4_test.rb"
|
6
|
+
require_relative "ipv4net_test.rb"
|
7
|
+
require_relative "ipv6_test.rb"
|
8
|
+
require_relative "ipv6net_test.rb"
|
9
|
+
require_relative "mask32_test.rb"
|
10
|
+
require_relative "mask128_test.rb"
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: netaddr
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 2.0.6
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Dustin Spinhirne
|
@@ -16,27 +16,32 @@ executables: []
|
|
16
16
|
extensions: []
|
17
17
|
extra_rdoc_files:
|
18
18
|
- README.md
|
19
|
-
-
|
20
|
-
- changelog
|
21
|
-
- license
|
19
|
+
- LICENSE
|
22
20
|
files:
|
23
|
-
-
|
21
|
+
- LICENSE
|
24
22
|
- README.md
|
25
|
-
-
|
26
|
-
- lib/
|
27
|
-
- lib/
|
28
|
-
- lib/
|
29
|
-
- lib/
|
30
|
-
- lib/
|
23
|
+
- lib/eui48.rb
|
24
|
+
- lib/eui64.rb
|
25
|
+
- lib/ipv4.rb
|
26
|
+
- lib/ipv4net.rb
|
27
|
+
- lib/ipv6.rb
|
28
|
+
- lib/ipv6net.rb
|
29
|
+
- lib/mask128.rb
|
30
|
+
- lib/mask32.rb
|
31
31
|
- lib/netaddr.rb
|
32
|
-
- lib/
|
33
|
-
-
|
34
|
-
-
|
35
|
-
- test/
|
36
|
-
- test/
|
37
|
-
- test/
|
38
|
-
- test/
|
39
|
-
|
32
|
+
- lib/util.rb
|
33
|
+
- test/eui48_test.rb
|
34
|
+
- test/eui64_test.rb
|
35
|
+
- test/examples.rb
|
36
|
+
- test/ipv4_test.rb
|
37
|
+
- test/ipv4net_test.rb
|
38
|
+
- test/ipv6_test.rb
|
39
|
+
- test/ipv6net_test.rb
|
40
|
+
- test/mask128_test.rb
|
41
|
+
- test/mask32_test.rb
|
42
|
+
- test/netaddr_test.rb
|
43
|
+
- test/run_all.rb
|
44
|
+
homepage: https://github.com/dspinhirne/netaddr-rb
|
40
45
|
licenses:
|
41
46
|
- Apache-2.0
|
42
47
|
metadata: {}
|
@@ -58,5 +63,5 @@ requirements: []
|
|
58
63
|
rubygems_version: 3.3.5
|
59
64
|
signing_key:
|
60
65
|
specification_version: 4
|
61
|
-
summary: A
|
66
|
+
summary: A Ruby library for performing calculations on IPv4 and IPv6 subnets.
|
62
67
|
test_files: []
|
data/Errors
DELETED
data/changelog
DELETED
@@ -1,52 +0,0 @@
|
|
1
|
-
Version 1.5.2
|
2
|
-
Changes:
|
3
|
-
* bug fixes from: https://github.com/KirillSmirnov, https://github.com/rwhitworth, https://github.com/y13i
|
4
|
-
|
5
|
-
Version 1.5.1
|
6
|
-
Changes:
|
7
|
-
* fixed bug with NetAddr#merge (credit to Daniel Boughton)
|
8
|
-
|
9
|
-
|
10
|
-
Version 1.5.0
|
11
|
-
Changes:
|
12
|
-
* fixed bug with EUI48#to_eui64 (credit to Erik Kline)
|
13
|
-
* fixed bug with u/l bit toggle on EUI#link_local (credit to Erik Kline)
|
14
|
-
* added EUI#to_ipv6
|
15
|
-
* added NetAddr#supernets
|
16
|
-
|
17
|
-
|
18
|
-
Version 1.4.0
|
19
|
-
Changes:
|
20
|
-
* Added additional options to NetAddr#sort
|
21
|
-
|
22
|
-
|
23
|
-
Version 1.3.0
|
24
|
-
New Features:
|
25
|
-
* added CIDR#[]
|
26
|
-
* added CIDR#succ (CIDR objects may now be used as args for the standard Ruby Range class)
|
27
|
-
* added CIDR#allocate_rfc3531
|
28
|
-
* added CIDR#to_i
|
29
|
-
* added CIDRv6.unique_local
|
30
|
-
* added EUI48#to_eui64
|
31
|
-
* added EUI#to_i
|
32
|
-
* added EUI#to_s
|
33
|
-
|
34
|
-
Changes:
|
35
|
-
* deprecated 'packed' methods
|
36
|
-
|
37
|
-
|
38
|
-
Version 1.2.0
|
39
|
-
Changes:
|
40
|
-
* CIDRv4#new and CIDRv6#new methods have been changed for the sake of speed improvements.
|
41
|
-
Please use the CIDR#create method instead.
|
42
|
-
* changes to CIDR#wildcard_mask
|
43
|
-
* bug fix with validate_eui method
|
44
|
-
* bug fix with validate_ip_addr
|
45
|
-
* bug fix and *vast* simplification of NetAddr.merge
|
46
|
-
|
47
|
-
|
48
|
-
New Features:
|
49
|
-
* speed improvements
|
50
|
-
* added CIDR#set_wildcard_mask
|
51
|
-
* added <=>, >, <, == methods to CIDR
|
52
|
-
* NetAddr.merge now reports which CIDR addresses were used to create new summary addresses
|