subnet_calc 0.3.1 → 0.3.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 1faa541b180b1e05028a169b0f6caba522666ff7
4
- data.tar.gz: 31b09138c648c9ed7223746b3d66872cbaa30f84
3
+ metadata.gz: 8a1eddfe72b1f9709ba8dc4bba337acb4e3b5948
4
+ data.tar.gz: d110a0f4455a9cb344f6b18e03f8606682b59139
5
5
  SHA512:
6
- metadata.gz: defd091462944103cd5443294504beb6dd9a8c7e82c195c1c477a71fb2db0a41c229d3efe2655969508381557a138edf30e9e6c228bd9458e61bd767916f846a
7
- data.tar.gz: ab60d4c82e57372b35e7cc94308557fb26f00fb12adf835b02588b747d307d2e762109026ae3ca974ec948a9e1c7027dca648758caddeb3556dd0db4bcb5cf52
6
+ metadata.gz: 7b1c0bb55656d10d346dd5b4f18d68a54ab0f7a867c26bb3830a2954cd38b94a7730addca35430085b4999f68a02e4cc6ca24233b79d39bb20e5fe6c10551e08
7
+ data.tar.gz: b98f890520e115843b3a2f1bcadce7b92d2606594d27b8122106f54de778856ae74b094a09b18aa9ada1f8f360536ee187588e0a7d079432682a7e05c20da2d2
checksums.yaml.gz.sig CHANGED
Binary file
data.tar.gz.sig CHANGED
Binary file
data/lib/subnet_calc.rb CHANGED
@@ -70,7 +70,7 @@ class SubnetCalc
70
70
  # ------------------------------------
71
71
 
72
72
 
73
- octet_n, col, class_type = if hosts then
73
+ octet_n, bit_n, class_type = if hosts then
74
74
 
75
75
  hosts_per_subnet = octets.flat_map.with_index do |octet,i|
76
76
  octet.bits.map.with_index {|y,j| [i, j, y.hosts_per_subnet] }
@@ -132,16 +132,15 @@ class SubnetCalc
132
132
  end
133
133
 
134
134
 
135
- bit = octets[octet_n].bits[col]
135
+ bit = octets[octet_n].bits[bit_n]
136
136
 
137
137
  magic_number, hosts_per_subnet, prefix = bit.decimal,
138
138
  bit.hosts_per_subnet, bit.prefix
139
139
 
140
- n = col
141
140
 
142
141
  # add the new mask to the octet
143
142
 
144
- octets[octet_n].mask = octets[octet_n].bits.map(&:decimal)[0..n].inject(:+)
143
+ octets[octet_n].mask = octets[octet_n].bits.map(&:decimal)[0..bit_n].inject(:+)
145
144
  subnet_mask = octets.map(&:mask).join('.')
146
145
 
147
146
  subnet_bits = (subnet_mask.split('.')[class_n]).to_i.to_s(2).count("1")
@@ -170,8 +169,7 @@ class SubnetCalc
170
169
  magic_number: magic_number,
171
170
  hosts: hosts_per_subnet - 2,
172
171
  subnet_mask: subnet_mask,
173
- subnet_bitmask: subnet_mask.split('.').map \
174
- {|x| ('0' * 7 + x.to_i.to_s(2))[-8..-1]},
172
+ subnet_bitmask: subnet_mask.split('.').map {|x| "%08d" % x.to_i.to_s(2)},
175
173
  prefix: prefix,
176
174
  subnets: subnets,
177
175
  range: "%s-%s" % [first_ip, last_ip],
@@ -288,9 +286,9 @@ EOF
288
286
  class_subnets(n, block_size) do |network, first, last, broadcast|
289
287
 
290
288
  {
291
- network: [network, 0].join('.'),
292
- first: [network, 1].join('.'),
293
- last: [broadcast, 254].join('.'),
289
+ network: [network, 0].join('.'),
290
+ first: [network, 1].join('.'),
291
+ last: [broadcast, 254].join('.'),
294
292
  broadcast: [broadcast, 255].join('.')
295
293
  }
296
294
 
@@ -303,15 +301,15 @@ EOF
303
301
  class_subnets(n, block_size) do |network, first, last, broadcast|
304
302
 
305
303
  {
306
- network: [network, 0, 0].join('.'),
307
- first: [network, 1, 1].join('.'),
308
- last: [broadcast, 255, 254].join('.'),
304
+ network: [network, 0, 0].join('.'),
305
+ first: [network, 1, 1].join('.'),
306
+ last: [broadcast, 255, 254].join('.'),
309
307
  broadcast: [broadcast, 255, 255].join('.')
310
308
  }
311
309
 
312
310
  end
313
311
 
314
- end
312
+ end
315
313
 
316
314
  def indent(s, i=2)
317
315
  s.lines.map{|x| ' ' * i + x}.join
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: subnet_calc
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.1
4
+ version: 0.3.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - James Robertson
metadata.gz.sig CHANGED
@@ -1 +1,2 @@
1
- �oi(>:�'�\��j���>��&O�<��n0�L��y��vs��t/Ki��u<�#]������I���j\��i�B;�Xg~��,8���?(����<���L��c�%�|MA��Emc�ٜ�>�-���h ���A����P�� �lsqw �0:SB(C[*F���H=�lHk��LM ��I�J����(��@��ݐ���D��P�S��0ަ�F>�i���K
1
+ ��e<�Zך?�����T՗˒3 �Z/ձ���w��:
2
+ ����4����ѷ�^T�A� �����k5�sk6m9�����syyM����ފ�-�8�{߱�(�'߻���3<�l�N�h��)�ў��\8�����~r���P�ay�N"� ul�-�3��J4f�L�]O"#J�<����h+�Bf�!�K�{������e0��f�́y��� 1.������:ԯ��z-;���� ���Kj�[