ipadmin 0.4.0 → 0.4.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (8) hide show
  1. data/README +166 -446
  2. data/lib/cidr.rb +132 -241
  3. data/lib/eui.rb +6 -40
  4. data/lib/methods.rb +28 -99
  5. data/lib/tree.rb +23 -144
  6. data/tests/cidr_test.rb +28 -17
  7. data/tests/tree_test.rb +2 -1
  8. metadata +4 -4
data/lib/eui.rb CHANGED
@@ -13,7 +13,7 @@ class EUI
13
13
  #==============================================================================#
14
14
 
15
15
  # - Arguments:
16
- # * EUI as a string, or a Hash with the following fields:
16
+ # * EUI as a String, or a Hash with the following fields:
17
17
  # - :EUI -- Extended Unique Identifier - String
18
18
  # - :PackedEUI -- Integer representing an Extended Unique Identifier (optional)
19
19
  #
@@ -74,11 +74,6 @@ class EUI
74
74
  end
75
75
  end
76
76
 
77
- #======================================#
78
- #
79
- #======================================#
80
-
81
-
82
77
  #==============================================================================#
83
78
  # address()
84
79
  #==============================================================================#
@@ -86,7 +81,7 @@ class EUI
86
81
  # Returns EUI address.
87
82
  #
88
83
  # - Arguments:
89
- # * Optional hash with the following fields:
84
+ # * Optional Hash with the following fields:
90
85
  # - :Delimiter -- delimitation character. valid values are (-,:,and .) (optional)
91
86
  #
92
87
  # - Returns:
@@ -138,11 +133,6 @@ class EUI
138
133
  return(address)
139
134
  end
140
135
 
141
- #======================================#
142
- #
143
- #======================================#
144
-
145
-
146
136
  #==============================================================================#
147
137
  # ei()
148
138
  #==============================================================================#
@@ -150,7 +140,7 @@ class EUI
150
140
  # Returns Extended Identifier portion of an EUI address (the vendor assigned ID).
151
141
  #
152
142
  # - Arguments:
153
- # * Optional hash with the following fields:
143
+ # * Optional Hash with the following fields:
154
144
  # - :Delimiter -- delimitation character. valid values are (-, and :) (optional)
155
145
  #
156
146
  # - Returns:
@@ -182,11 +172,6 @@ class EUI
182
172
  return(ei)
183
173
  end
184
174
 
185
- #======================================#
186
- #
187
- #======================================#
188
-
189
-
190
175
  #==============================================================================#
191
176
  # link_local()
192
177
  #==============================================================================#
@@ -194,7 +179,7 @@ class EUI
194
179
  # Provide an IPv6 Link Local address based on the current EUI address.
195
180
  #
196
181
  # - Arguments:
197
- # * Optional hash with the following fields:
182
+ # * Optional Hash with the following fields:
198
183
  # - :Short -- if true, return IPv6 addresses in short-hand notation (optional)
199
184
  # - :Objectify -- if true, return CIDR objects (optional)
200
185
  #
@@ -240,11 +225,6 @@ class EUI
240
225
  return(link_local)
241
226
  end
242
227
 
243
- #======================================#
244
- #
245
- #======================================#
246
-
247
-
248
228
  #==============================================================================#
249
229
  # oui()
250
230
  #==============================================================================#
@@ -252,7 +232,7 @@ class EUI
252
232
  # Returns Organizationally Unique Identifier portion of an EUI address (the vendor ID).
253
233
  #
254
234
  # - Arguments:
255
- # * Optional hash with the following fields:
235
+ # * Optional Hash with the following fields:
256
236
  # - :Delimiter -- delimitation character. valid values are (-, and :) (optional)
257
237
  #
258
238
  # - Returns:
@@ -284,11 +264,6 @@ class EUI
284
264
  return(oui)
285
265
  end
286
266
 
287
- #======================================#
288
- #
289
- #======================================#
290
-
291
-
292
267
 
293
268
  # PRIVATE METHODS
294
269
  private
@@ -317,11 +292,6 @@ private
317
292
  return(octets)
318
293
  end
319
294
 
320
- #======================================#
321
- #
322
- #======================================#
323
-
324
-
325
295
  #==============================================================================#
326
296
  # unpack_oui()
327
297
  #==============================================================================#
@@ -338,11 +308,7 @@ private
338
308
  return(octets)
339
309
  end
340
310
 
341
- #======================================#
342
- #
343
- #======================================#
344
-
345
- end
311
+ end # class EUI
346
312
 
347
313
  # EUI-48 Address - Inherits all methods from IPAdmin::EUI.
348
314
  # Addresses of this type have a 24-bit OUI and a 24-bit EI.
@@ -8,7 +8,7 @@ module IPAdmin
8
8
  # is the supernet of the other.
9
9
  #
10
10
  # - Arguments:
11
- # * (2) CIDR addresses or IPAdmin::CIDR objects
11
+ # * (2) Strings, or (2) IPAdmin::CIDR objects
12
12
  #
13
13
  # - Returns:
14
14
  # * if one is a subnet of another, then return original array in order of [supernet,subnet]
@@ -16,8 +16,10 @@ module IPAdmin
16
16
  # * if neither is a supernet of the other, return nil
17
17
  #
18
18
  # Examples:
19
- # supernet,subnet = IPAdmin.compare(cidr1,cidr2)
20
- # supernet,subnet = IPAdmin.compare('192.168.1.0/24','192.168.1.32/27')
19
+ # comp1 = IPAdmin.compare(cidr4_1,cidr4_2)
20
+ # comp2 = IPAdmin.compare(cidr6_1,cidr6_2)
21
+ # puts "#{(comp1[0]).desc} is the supernet of #{(comp1[1]).desc}"
22
+ # puts "#{(comp2[0]).desc} is the supernet of #{(comp2[1]).desc}"
21
23
  #
22
24
 
23
25
  def compare(cidr1,cidr2)
@@ -80,11 +82,6 @@ def compare(cidr1,cidr2)
80
82
  end
81
83
  module_function :compare
82
84
 
83
- #======================================#
84
- #
85
- #======================================#
86
-
87
-
88
85
  #==============================================================================#
89
86
  # merge()
90
87
  #==============================================================================#
@@ -97,7 +94,7 @@ module_function :compare
97
94
  # 192.168.0.0/23 and 192.168.2.0/24 rather than into 192.168.0.0/22
98
95
  #
99
96
  # - Arguments:
100
- # * Array of CIDR addresses or IPAdmin::CIDR objects, or a Hash with
97
+ # * Array of Strings, Array of IPAdmin::CIDR objects, or a Hash with
101
98
  # the following fields:
102
99
  # - :List -- Array of CIDR addresses or IPAdmin::CIDR objects
103
100
  # - :Objectify -- if true, return IPAdmin::CIDR objects (optional)
@@ -108,7 +105,7 @@ module_function :compare
108
105
  #
109
106
  # - Notes:
110
107
  # * I have designed this with enough flexibility that you can pass in CIDR
111
- # addresses that arent even related (ex. 192.168.1.0/26, 192.168.1.64/26,
108
+ # addresses that arent even related (ex. 192.168.1.0/26, 192.168.1.64/27, 192.168.1.96/27
112
109
  # 10.1.0.0/26, 10.1.0.64/26) and they will be merged properly (ie 192.168.1.0/25,
113
110
  # and 10.1.0.0/25 would be returned).
114
111
  #
@@ -264,11 +261,6 @@ def merge(options)
264
261
  end
265
262
  module_function :merge
266
263
 
267
- #======================================#
268
- #
269
- #======================================#
270
-
271
-
272
264
  #==============================================================================#
273
265
  # minimum_size()
274
266
  #==============================================================================#
@@ -277,7 +269,7 @@ module_function :merge
277
269
  # netmask (in bits) required for that subnet.
278
270
  #
279
271
  # - Arguments:
280
- # * Integer or Hash with the following fields:
272
+ # * Integer or a Hash with the following fields:
281
273
  # - :IPCount -- the number of IP addresses required - Integer
282
274
  # - :Version -- IP version - Integer(optional)
283
275
  #
@@ -332,16 +324,11 @@ def minimum_size(options)
332
324
  end
333
325
  module_function :minimum_size
334
326
 
335
- #======================================#
336
- #
337
- #======================================#
338
-
339
-
340
327
  #==============================================================================#
341
328
  # pack_ip_addr()
342
329
  #==============================================================================#
343
330
 
344
- # Convert IP addresses into an integer.
331
+ # Convert IP addresses into an Integer.
345
332
  #
346
333
  # - Arguments:
347
334
  # * IP address as a String, or a Hash with the following fields:
@@ -462,21 +449,16 @@ def pack_ip_addr(options)
462
449
  end
463
450
  module_function :pack_ip_addr
464
451
 
465
- #======================================#
466
- #
467
- #======================================#
468
-
469
-
470
452
  #==============================================================================#
471
453
  # pack_ip_netmask()
472
454
  #==============================================================================#
473
455
 
474
- # Convert IP netmask into an integer.Netmask may be in either CIDR (/yy) or
456
+ # Convert IP netmask into an Integer. Netmask may be in either CIDR (/yy) or
475
457
  # extended (y.y.y.y) format. CIDR formatted netmasks may either
476
458
  # be a String or an Integer.
477
459
  #
478
460
  # - Arguments
479
- # * Netmask as a String, or a Integer, or a Hash with the following fields:
461
+ # * String or Integer, or a Hash with the following fields:
480
462
  # - :Netmask -- Netmask - String or Integer
481
463
  # - :Version -- IP version - Integer (optional)
482
464
  #
@@ -484,7 +466,8 @@ module_function :pack_ip_addr
484
466
  # * Integer
485
467
  #
486
468
  # - Notes:
487
- # * Version defaults to 4
469
+ # * Version defaults to 4. It may be necessary to specify the version if
470
+ # an IPv6 netmask of /32 or smaller were passed.
488
471
  #
489
472
  # Examples:
490
473
  # packed = IPAdmin.pack_ip_netmask('255.255.255.0')
@@ -552,11 +535,6 @@ def pack_ip_netmask(options)
552
535
  end
553
536
  module_function :pack_ip_netmask
554
537
 
555
- #======================================#
556
- #
557
- #======================================#
558
-
559
-
560
538
  #==============================================================================#
561
539
  # range()
562
540
  #==============================================================================#
@@ -565,17 +543,17 @@ module_function :pack_ip_netmask
565
543
  # return all IP addresses between them.
566
544
  #
567
545
  # - Arguments:
568
- # * Array of (2)CIDR addresses or IPAdmin::CIDR objects, or a Hash
546
+ # * Array of (2) Strings, Array of (2) IPAdmin::CIDR objects, or a Hash
569
547
  # with the following fields:
570
548
  # - :Bitstep -- enumerate in X sized steps - Integer (optional)
571
- # - :Boundaries -- array of (2) CIDR addresses or IPAdmin::CIDR objects
549
+ # - :Boundaries -- Array of (2) Strings, or Array of (2) IPAdmin::CIDR objects
572
550
  # - :Inclusive -- if true, include boundaries in returned data
573
551
  # - :Limit -- limit returned list to X number of items - Integer (optional)
574
552
  # - :Objectify -- if true, return CIDR objects (optional)
575
553
  # - :Short -- if true, return IPv6 addresses in short-hand notation (optional)
576
554
  #
577
555
  # - Returns:
578
- # * Array of CIDR address Strings or IPAdmin::CIDR objects
556
+ # * Array of Strings, or Array of IPAdmin::CIDR objects
579
557
  #
580
558
  # - Notes:
581
559
  # * IPAdmin.range will use the original IP address passed during the initialization
@@ -691,11 +669,6 @@ def range(options)
691
669
  end
692
670
  module_function :range
693
671
 
694
- #======================================#
695
- #
696
- #======================================#
697
-
698
-
699
672
  #==============================================================================#
700
673
  # shorten()
701
674
  #==============================================================================#
@@ -704,7 +677,7 @@ module_function :range
704
677
  # The address should not contain a netmask.
705
678
  #
706
679
  # - Arguments:
707
- # * IP address as a String
680
+ # * String
708
681
  #
709
682
  # - Returns:
710
683
  # * String
@@ -787,11 +760,6 @@ def shorten(addr)
787
760
  end
788
761
  module_function :shorten
789
762
 
790
- #======================================#
791
- #
792
- #======================================#
793
-
794
-
795
763
  #==============================================================================#
796
764
  # sort()
797
765
  #==============================================================================#
@@ -800,10 +768,10 @@ module_function :shorten
800
768
  # sort them from lowest to highest by Network/Netmask.
801
769
  #
802
770
  # - Arguments:
803
- # * Array of CIDR addresses or IPAdmin::CIDR objects
771
+ # * Array of Strings, or Array of IPAdmin::CIDR objects
804
772
  #
805
773
  # - Returns:
806
- # * Array of CIDR address Strings or IPAdmin::CIDR objects
774
+ # * Array of Strings, or Array of IPAdmin::CIDR objects
807
775
  #
808
776
  # - Notes:
809
777
  # * IPAdmin.sort will use the original IP address passed during the initialization
@@ -811,7 +779,7 @@ module_function :shorten
811
779
  #
812
780
  # Examples:
813
781
  # sorted = IPAdmin.sort([cidr1,cidr2])
814
- # sorted = IPAdmin.sort(['192.168.1.32/27','192.168.1.0/27'])
782
+ # sorted = IPAdmin.sort(['192.168.1.32/27','192.168.1.0/27','192.168.2.0/24'])
815
783
  #
816
784
  def sort(list)
817
785
 
@@ -868,11 +836,6 @@ def sort(list)
868
836
  end
869
837
  module_function :sort
870
838
 
871
- #======================================#
872
- #
873
- #======================================#
874
-
875
-
876
839
  #==============================================================================#
877
840
  # unpack_ip_addr()
878
841
  #==============================================================================#
@@ -880,7 +843,7 @@ module_function :sort
880
843
  # Unack a packed IP address back into a printable string.
881
844
  #
882
845
  # - Arguments:
883
- # * Integer or a Hash with the following fields:
846
+ # * Integer, or a Hash with the following fields:
884
847
  # - :Integer -- Integer representaion of an IP address
885
848
  # - :Version -- IP version - Integer (optional)
886
849
  # - :IPv4Mapped -- if true, unpack IPv6 as an IPv4 mapped address (optional)
@@ -978,20 +941,15 @@ def unpack_ip_addr(options)
978
941
  end
979
942
  module_function :unpack_ip_addr
980
943
 
981
- #======================================#
982
- #
983
- #======================================#
984
-
985
-
986
944
  #==============================================================================#
987
945
  # unpack_ip_netmask()
988
946
  #==============================================================================#
989
947
 
990
- # Unack a packed IP netmask into a integer representing the number of
948
+ # Unpack a packed IP netmask into an Integer representing the number of
991
949
  # bits in the CIDR mask.
992
950
  #
993
951
  # - Arguments:
994
- # * Integer or a Hash with the following fields:
952
+ # * Integer, or a Hash with the following fields:
995
953
  # - :Integer -- Integer representation of an IP Netmask
996
954
  #
997
955
  # - Returns:
@@ -1042,11 +1000,6 @@ def unpack_ip_netmask(options)
1042
1000
  end
1043
1001
  module_function :unpack_ip_netmask
1044
1002
 
1045
- #======================================#
1046
- #
1047
- #======================================#
1048
-
1049
-
1050
1003
  #==============================================================================#
1051
1004
  # unshorten()
1052
1005
  #==============================================================================#
@@ -1055,7 +1008,7 @@ module_function :unpack_ip_netmask
1055
1008
  # notation. The address should not contain a netmask.
1056
1009
  #
1057
1010
  # - Arguments:
1058
- # * IP address as a String
1011
+ # * String
1059
1012
  #
1060
1013
  # - Returns:
1061
1014
  # * String
@@ -1084,11 +1037,6 @@ def unshorten(addr)
1084
1037
  end
1085
1038
  module_function :unshorten
1086
1039
 
1087
- #======================================#
1088
- #
1089
- #======================================#
1090
-
1091
-
1092
1040
  #==============================================================================#
1093
1041
  # validate_eui()
1094
1042
  #==============================================================================#
@@ -1096,7 +1044,7 @@ module_function :unshorten
1096
1044
  # Validate an EUI-48 or EUI-64 address.
1097
1045
  #
1098
1046
  # - Arguments
1099
- # * EUI address as a String, or a Hash with the following fields:
1047
+ # * String, or a Hash with the following fields:
1100
1048
  # - :EUI -- Address to validate - String
1101
1049
  #
1102
1050
  # - Returns:
@@ -1151,11 +1099,6 @@ def validate_eui(options)
1151
1099
  end
1152
1100
  module_function :validate_eui
1153
1101
 
1154
- #======================================#
1155
- #
1156
- #======================================#
1157
-
1158
-
1159
1102
  #==============================================================================#
1160
1103
  # validate_ip_addr()
1161
1104
  #==============================================================================#
@@ -1163,7 +1106,7 @@ module_function :validate_eui
1163
1106
  # Validate an IP address. The address should not contain a netmask.
1164
1107
  #
1165
1108
  # - Arguments
1166
- # * IP address as a String or Integer, or a Hash with the following fields:
1109
+ # * String or Integer, or a Hash with the following fields:
1167
1110
  # - :IP -- IP address to validate - String or Integer
1168
1111
  # - :Version -- IP version - Integer (optional)
1169
1112
  #
@@ -1318,11 +1261,6 @@ def validate_ip_addr(options)
1318
1261
  end
1319
1262
  module_function :validate_ip_addr
1320
1263
 
1321
- #======================================#
1322
- #
1323
- #======================================#
1324
-
1325
-
1326
1264
  #==============================================================================#
1327
1265
  # validate_ip_netmask()
1328
1266
  #==============================================================================#
@@ -1330,7 +1268,7 @@ module_function :validate_ip_addr
1330
1268
  # Validate IP Netmask.
1331
1269
  #
1332
1270
  # - Arguments:
1333
- # * Netmask as a String or Integer, or a Hash with the following fields:
1271
+ # * String or Integer, or a Hash with the following fields:
1334
1272
  # - :Netmask -- Netmask to validate - String or Integer
1335
1273
  # - :Packed -- if true, the provided Netmask is a packed Integer
1336
1274
  # - :Version -- IP version - Integer (optional)
@@ -1450,11 +1388,6 @@ def validate_ip_netmask(options)
1450
1388
  end
1451
1389
  module_function :validate_ip_netmask
1452
1390
 
1453
- #======================================#
1454
- #
1455
- #======================================#
1456
-
1457
-
1458
1391
  #==============================================================================#
1459
1392
  # NetStruct
1460
1393
  #==============================================================================#
@@ -1469,11 +1402,7 @@ module_function :validate_ip_netmask
1469
1402
  #
1470
1403
  NetStruct = Struct.new(:cidr, :parent, :children)
1471
1404
 
1472
- #======================================#
1473
- #
1474
- #======================================#
1475
-
1405
+ end # module IPAdmin
1476
1406
 
1477
- end
1478
1407
  __END__
1479
1408