netaddr 1.5.1 → 1.5.3
Sign up to get free protection for your applications and to get access to all the features.
Potentially problematic release.
This version of netaddr might be problematic. Click here for more details.
- checksums.yaml +5 -5
- data/README.md +9 -0
- data/changelog +15 -21
- data/lib/cidr.rb +17 -192
- data/lib/cidr_shortcuts.rb +0 -39
- data/lib/eui.rb +3 -64
- data/lib/ip_math.rb +0 -32
- data/lib/methods.rb +1 -67
- data/lib/netaddr.rb +6 -12
- data/lib/tree.rb +2 -107
- data/lib/validation_shortcuts.rb +0 -18
- data/test/cidr_test.rb +2 -1
- data/test/eui_test.rb +1 -1
- data/test/methods_test.rb +1 -1
- data/test/tree_test.rb +1 -1
- metadata +5 -6
- data/README +0 -17
data/lib/tree.rb
CHANGED
@@ -1,9 +1,3 @@
|
|
1
|
-
=begin rdoc
|
2
|
-
Copyleft (c) 2006 Dustin Spinhirne
|
3
|
-
|
4
|
-
Licensed under the same terms as Ruby, No Warranty is provided.
|
5
|
-
=end
|
6
|
-
|
7
1
|
module NetAddr
|
8
2
|
|
9
3
|
#=Tree
|
@@ -29,10 +23,6 @@ module NetAddr
|
|
29
23
|
#
|
30
24
|
class Tree
|
31
25
|
|
32
|
-
#==============================================================================#
|
33
|
-
# initialize()
|
34
|
-
#==============================================================================#
|
35
|
-
|
36
26
|
#===Synopsis
|
37
27
|
#Create a new Tree object.
|
38
28
|
#
|
@@ -48,10 +38,6 @@ class Tree
|
|
48
38
|
@v6_root = NetAddr::CIDRv6.new(0,0,{:Subnets => []})
|
49
39
|
end
|
50
40
|
|
51
|
-
#==============================================================================#
|
52
|
-
# add!()
|
53
|
-
#==============================================================================#
|
54
|
-
|
55
41
|
#===Synopsis
|
56
42
|
# Add a CIDR address or NetAddr::CIDR object to the tree.
|
57
43
|
# Example:
|
@@ -84,10 +70,6 @@ class Tree
|
|
84
70
|
return(nil)
|
85
71
|
end
|
86
72
|
|
87
|
-
#==============================================================================#
|
88
|
-
# ancestors()
|
89
|
-
#==============================================================================#
|
90
|
-
|
91
73
|
#===Synopsis
|
92
74
|
# Returns all the ancestors of the provided CIDR addresses.
|
93
75
|
#
|
@@ -121,10 +103,6 @@ class Tree
|
|
121
103
|
return(list)
|
122
104
|
end
|
123
105
|
|
124
|
-
#==============================================================================#
|
125
|
-
# children()
|
126
|
-
#==============================================================================#
|
127
|
-
|
128
106
|
#===Synopsis
|
129
107
|
# Returns all the immediate children of the provided CIDR addresses.
|
130
108
|
#
|
@@ -159,10 +137,6 @@ class Tree
|
|
159
137
|
return(list)
|
160
138
|
end
|
161
139
|
|
162
|
-
#==============================================================================#
|
163
|
-
# descendants
|
164
|
-
#==============================================================================#
|
165
|
-
|
166
140
|
#===Synopsis
|
167
141
|
# Return all descendants of the provided CIDR address.
|
168
142
|
#
|
@@ -199,10 +173,6 @@ class Tree
|
|
199
173
|
return(list)
|
200
174
|
end
|
201
175
|
|
202
|
-
#==============================================================================#
|
203
|
-
# delete!()
|
204
|
-
#==============================================================================#
|
205
|
-
|
206
176
|
#===Synopsis
|
207
177
|
# Remove the provided CIDR address from the tree.
|
208
178
|
#
|
@@ -243,10 +213,6 @@ class Tree
|
|
243
213
|
return(removed)
|
244
214
|
end
|
245
215
|
|
246
|
-
#==============================================================================#
|
247
|
-
# dump
|
248
|
-
#==============================================================================#
|
249
|
-
|
250
216
|
#===Synopsis
|
251
217
|
# Dump the contents of this tree.
|
252
218
|
#
|
@@ -268,10 +234,6 @@ class Tree
|
|
268
234
|
return(list)
|
269
235
|
end
|
270
236
|
|
271
|
-
#==============================================================================#
|
272
|
-
# exists?()
|
273
|
-
#==============================================================================#
|
274
|
-
|
275
237
|
#===Synopsis
|
276
238
|
# Has a CIDR address already been added to the tree?
|
277
239
|
#
|
@@ -301,10 +263,6 @@ class Tree
|
|
301
263
|
return(found)
|
302
264
|
end
|
303
265
|
|
304
|
-
#==============================================================================#
|
305
|
-
# fill_in!()
|
306
|
-
#==============================================================================#
|
307
|
-
|
308
266
|
#===Synopsis
|
309
267
|
# Fill in the missing subnets of a particular CIDR.
|
310
268
|
#
|
@@ -341,10 +299,6 @@ class Tree
|
|
341
299
|
return(filled)
|
342
300
|
end
|
343
301
|
|
344
|
-
#==============================================================================#
|
345
|
-
# find()
|
346
|
-
#==============================================================================#
|
347
|
-
|
348
302
|
#===Synopsis
|
349
303
|
# Find and return a CIDR from within the tree.
|
350
304
|
#
|
@@ -375,10 +329,6 @@ class Tree
|
|
375
329
|
return(me)
|
376
330
|
end
|
377
331
|
|
378
|
-
#==============================================================================#
|
379
|
-
# find_space()
|
380
|
-
#==============================================================================#
|
381
|
-
|
382
332
|
#===Synopsis
|
383
333
|
# Find subnets that are of at least size X. Only subnets that are not themselves
|
384
334
|
# subnetted will be returned. :Subnet takes precedence over :IPCount
|
@@ -446,10 +396,6 @@ class Tree
|
|
446
396
|
return(new_list)
|
447
397
|
end
|
448
398
|
|
449
|
-
#==============================================================================#
|
450
|
-
# longest_match()
|
451
|
-
#==============================================================================#
|
452
|
-
|
453
399
|
#===Synopsis
|
454
400
|
#Find the longest matching branch of our tree to which a
|
455
401
|
#CIDR address belongs. Useful for performing 'routing table' style lookups.
|
@@ -479,10 +425,6 @@ class Tree
|
|
479
425
|
return( NetAddr.cidr_build(found.version, found.to_i(:network), found.to_i(:netmask)) )
|
480
426
|
end
|
481
427
|
|
482
|
-
#==============================================================================#
|
483
|
-
# prune!()
|
484
|
-
#==============================================================================#
|
485
|
-
|
486
428
|
#===Synopsis
|
487
429
|
# Remove all subnets of the provided CIDR address.
|
488
430
|
#
|
@@ -518,10 +460,6 @@ class Tree
|
|
518
460
|
return(pruned)
|
519
461
|
end
|
520
462
|
|
521
|
-
#==============================================================================#
|
522
|
-
# remove!()
|
523
|
-
#==============================================================================#
|
524
|
-
|
525
463
|
#===Synopsis
|
526
464
|
# Remove the provided CIDR address, and all of its subnets from the tree.
|
527
465
|
#
|
@@ -559,10 +497,6 @@ class Tree
|
|
559
497
|
return(removed)
|
560
498
|
end
|
561
499
|
|
562
|
-
#==============================================================================#
|
563
|
-
# resize!()
|
564
|
-
#==============================================================================#
|
565
|
-
|
566
500
|
#===Synopsis
|
567
501
|
# Resize the provided CIDR address.
|
568
502
|
#
|
@@ -601,10 +535,6 @@ class Tree
|
|
601
535
|
return(resized)
|
602
536
|
end
|
603
537
|
|
604
|
-
#==============================================================================#
|
605
|
-
# root()
|
606
|
-
#==============================================================================#
|
607
|
-
|
608
538
|
#===Synopsis
|
609
539
|
# Returns the root of the provided CIDR address.
|
610
540
|
#
|
@@ -640,10 +570,6 @@ class Tree
|
|
640
570
|
return( NetAddr.cidr_build(parent.version, parent.to_i(:network), parent.to_i(:netmask)) )
|
641
571
|
end
|
642
572
|
|
643
|
-
#==============================================================================#
|
644
|
-
# show()
|
645
|
-
#==============================================================================#
|
646
|
-
|
647
573
|
#===Synopsis
|
648
574
|
# Print the tree as a formatted string.
|
649
575
|
#
|
@@ -692,10 +618,6 @@ class Tree
|
|
692
618
|
return(printed)
|
693
619
|
end
|
694
620
|
|
695
|
-
#==============================================================================#
|
696
|
-
# siblings()
|
697
|
-
#==============================================================================#
|
698
|
-
|
699
621
|
#===Synopsis
|
700
622
|
# Return list of the sibling CIDRs of the provided CIDR address.
|
701
623
|
#
|
@@ -729,10 +651,6 @@ class Tree
|
|
729
651
|
return(list)
|
730
652
|
end
|
731
653
|
|
732
|
-
#==============================================================================#
|
733
|
-
# summarize_subnets!()
|
734
|
-
#==============================================================================#
|
735
|
-
|
736
654
|
#===Synopsis
|
737
655
|
# Summarize all subnets of the provided CIDR address. The subnets will be
|
738
656
|
# placed under the new summary address within the tree.
|
@@ -771,10 +689,6 @@ class Tree
|
|
771
689
|
end
|
772
690
|
alias :merge_subnets! :summarize_subnets!
|
773
691
|
|
774
|
-
#==============================================================================#
|
775
|
-
# supernets()
|
776
|
-
#==============================================================================#
|
777
|
-
|
778
692
|
#===Synopsis
|
779
693
|
# Return list of the top-level supernets of this tree.
|
780
694
|
#
|
@@ -795,12 +709,9 @@ class Tree
|
|
795
709
|
end
|
796
710
|
|
797
711
|
|
798
|
-
# PRIVATE INSTANCE METHODS
|
799
|
-
private
|
800
712
|
|
801
|
-
|
802
|
-
|
803
|
-
#==============================================================================#
|
713
|
+
|
714
|
+
private
|
804
715
|
|
805
716
|
# Add NetStruct object to an array of NetStruct's
|
806
717
|
#
|
@@ -831,10 +742,6 @@ private
|
|
831
742
|
return(nil)
|
832
743
|
end
|
833
744
|
|
834
|
-
#==============================================================================#
|
835
|
-
# add_to_tree()
|
836
|
-
#==============================================================================#
|
837
|
-
|
838
745
|
# Add CIDR to a Tree
|
839
746
|
#
|
840
747
|
def add_to_tree(cidr,root=nil)
|
@@ -844,10 +751,6 @@ private
|
|
844
751
|
return(nil)
|
845
752
|
end
|
846
753
|
|
847
|
-
#==============================================================================#
|
848
|
-
# dump_children()
|
849
|
-
#==============================================================================#
|
850
|
-
|
851
754
|
# Dump contents of an Array of NetStruct objects
|
852
755
|
#
|
853
756
|
def dump_children(parent,depth=0)
|
@@ -864,10 +767,6 @@ private
|
|
864
767
|
return(list)
|
865
768
|
end
|
866
769
|
|
867
|
-
#==============================================================================#
|
868
|
-
# find_me()
|
869
|
-
#==============================================================================#
|
870
|
-
|
871
770
|
# Find the NetStruct to which a cidr belongs.
|
872
771
|
#
|
873
772
|
def find_me(cidr)
|
@@ -887,10 +786,6 @@ private
|
|
887
786
|
return(me)
|
888
787
|
end
|
889
788
|
|
890
|
-
#==============================================================================#
|
891
|
-
# find_parent()
|
892
|
-
#==============================================================================#
|
893
|
-
|
894
789
|
# Find the parent NetStruct to which a child NetStruct belongs.
|
895
790
|
#
|
896
791
|
def find_parent(cidr,parent=nil)
|
data/lib/validation_shortcuts.rb
CHANGED
@@ -1,10 +1,6 @@
|
|
1
1
|
module NetAddr
|
2
2
|
private
|
3
3
|
|
4
|
-
#==============================================================================#
|
5
|
-
# validate_args()
|
6
|
-
#==============================================================================#
|
7
|
-
|
8
4
|
# validate options hash
|
9
5
|
#
|
10
6
|
def validate_args(to_validate,known_args)
|
@@ -15,10 +11,6 @@ def validate_args(to_validate,known_args)
|
|
15
11
|
end
|
16
12
|
module_function :validate_args
|
17
13
|
|
18
|
-
#==============================================================================#
|
19
|
-
# validate_ip_int()
|
20
|
-
#==============================================================================#
|
21
|
-
|
22
14
|
def validate_ip_int(ip,version)
|
23
15
|
version = 4 if (!version && ip < 2**32)
|
24
16
|
if (version == 4)
|
@@ -31,10 +23,6 @@ def validate_ip_int(ip,version)
|
|
31
23
|
end
|
32
24
|
module_function :validate_ip_int
|
33
25
|
|
34
|
-
#==============================================================================#
|
35
|
-
# validate_ip_str()
|
36
|
-
#==============================================================================#
|
37
|
-
|
38
26
|
def validate_ip_str(ip,version)
|
39
27
|
# check validity of charaters
|
40
28
|
if (ip =~ /[^0-9a-fA-F\.:]/)
|
@@ -129,9 +117,6 @@ def validate_ip_str(ip,version)
|
|
129
117
|
end
|
130
118
|
module_function :validate_ip_str
|
131
119
|
|
132
|
-
#==============================================================================#
|
133
|
-
# validate_netmask_int()
|
134
|
-
#==============================================================================#
|
135
120
|
def validate_netmask_int(netmask,version,is_int=false)
|
136
121
|
address_len = 32
|
137
122
|
address_len = 128 if (version == 6)
|
@@ -149,9 +134,6 @@ def validate_netmask_int(netmask,version,is_int=false)
|
|
149
134
|
end
|
150
135
|
module_function :validate_netmask_int
|
151
136
|
|
152
|
-
#==============================================================================#
|
153
|
-
# validate_netmask_str()
|
154
|
-
#==============================================================================#
|
155
137
|
def validate_netmask_str(netmask,version)
|
156
138
|
address_len = 32
|
157
139
|
address_len = 128 if (version == 6)
|
data/test/cidr_test.rb
CHANGED
data/test/eui_test.rb
CHANGED
data/test/methods_test.rb
CHANGED
data/test/tree_test.rb
CHANGED
metadata
CHANGED
@@ -1,27 +1,27 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: netaddr
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.5.
|
4
|
+
version: 1.5.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Dustin Spinhirne
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2022-07-08 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description:
|
14
14
|
email:
|
15
15
|
executables: []
|
16
16
|
extensions: []
|
17
17
|
extra_rdoc_files:
|
18
|
-
- README
|
18
|
+
- README.md
|
19
19
|
- Errors
|
20
20
|
- changelog
|
21
21
|
- license
|
22
22
|
files:
|
23
23
|
- Errors
|
24
|
-
- README
|
24
|
+
- README.md
|
25
25
|
- changelog
|
26
26
|
- lib/cidr.rb
|
27
27
|
- lib/cidr_shortcuts.rb
|
@@ -55,8 +55,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
55
55
|
- !ruby/object:Gem::Version
|
56
56
|
version: '0'
|
57
57
|
requirements: []
|
58
|
-
|
59
|
-
rubygems_version: 2.2.2
|
58
|
+
rubygems_version: 3.3.5
|
60
59
|
signing_key:
|
61
60
|
specification_version: 4
|
62
61
|
summary: A package for manipulating network addresses.
|
data/README
DELETED
@@ -1,17 +0,0 @@
|
|
1
|
-
=Introduction
|
2
|
-
|
3
|
-
NetAddr arose through my need as a network engineer for a
|
4
|
-
back-end module that could easily handle such advanced tasks
|
5
|
-
as automating the subnetting/supernetting
|
6
|
-
of IP space, performing calculations on IP CIDR blocks, and other
|
7
|
-
various items. At that time there were no modules that could
|
8
|
-
do any of the things that I needed, so I set out to create my own.
|
9
|
-
Since it has proven to be fairly useful to me, I have decided to share the
|
10
|
-
code with the Ruby community.
|
11
|
-
|
12
|
-
I have added things that I find immediately useful for me. I am
|
13
|
-
open to suggestions if there is something that I could add to make
|
14
|
-
your life easier.
|
15
|
-
|
16
|
-
Dustin Spinhirne
|
17
|
-
|