subnet_calc 0.3.0 → 0.3.4

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
- SHA1:
3
- metadata.gz: ed194bf35fe325fc2fb62ea861140f63c0f6b5ac
4
- data.tar.gz: 48a9537735c184f33cc7f170364c157e0b7bdcbc
2
+ SHA256:
3
+ metadata.gz: 704ba733fc18df391c8e1c226a80d6b4211afdbb859038be24a8b1b79da15dfd
4
+ data.tar.gz: bb2c85e9364aa9503a5b8c299967e87f8a384c9dbc03f0ae0330989f82dbc152
5
5
  SHA512:
6
- metadata.gz: 37e0e8c28058efe0a2e8a7616e05f778d89faf799a4ad459fc14b442622e9c79a6860c864ba29d561dfa9875ad33f9bfa0c1cdf7d3a5fea09c645bf1597e830a
7
- data.tar.gz: f12f12f39424d089ca56299099327b01c13cab8725dedaa0b4162f2e77913a98c16ac29f384382ece6db222f9a0477b1e603a6b5432ee69f7eb406672518f1fa
6
+ metadata.gz: 984d0441e4452864f39246a00b100a5dd4b97ebc941185bcc2ee35620d582fbc51aa9467d7308e49012e3e3a19f9c9c306662067e1da2c2c1474a36972066bed
7
+ data.tar.gz: c56ac4cb0a20a1623f06d3c40ecccbc31df366c812dbaa10959bf4d5a8b7850a8c8b97886674eb91c47b7d9ba234946e0e0648eb231a3e4d1db1b896969bda2e
checksums.yaml.gz.sig CHANGED
Binary file
data/lib/subnet_calc.rb CHANGED
@@ -10,7 +10,7 @@ require 'table-formatter'
10
10
 
11
11
  module Ordinals
12
12
 
13
- refine Fixnum do
13
+ refine Integer do
14
14
  def ordinal
15
15
  self.to_s + ( (10...20).include?(self) ? 'th' :
16
16
  %w{ th st nd rd th th th th th th }[self % 10] )
@@ -27,7 +27,7 @@ class SubnetCalc
27
27
  def initialize(inputs={})
28
28
 
29
29
  @inputs = inputs
30
- default_inputs = {hosts: nil, ip: '192.168.0.0', prefix: nil}.merge(inputs)
30
+ default_inputs = {hosts: nil, ip: nil, prefix: nil}.merge(inputs)
31
31
 
32
32
  # Using the input(s) supplied:
33
33
 
@@ -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")
@@ -157,7 +156,9 @@ class SubnetCalc
157
156
  class_a_subnets(256 ** 2 / segments, bit.decimal)
158
157
  end
159
158
 
160
- ip = (default_inputs[:ip] + ' ') .split('.')[0..octet_n-1]
159
+ default_inputs[:ip] ||= ['10.0.0.0', '172.16.0.0','192.166.0.0'][class_n-1]
160
+
161
+ ip = (default_inputs[:ip] + ' ') .split('.')[0..class_n-1]
161
162
 
162
163
  first_ip = (ip + [subnets.first.first]).join('.')
163
164
  last_ip = (ip + [subnets.first.last]).join('.')
@@ -168,8 +169,7 @@ class SubnetCalc
168
169
  magic_number: magic_number,
169
170
  hosts: hosts_per_subnet - 2,
170
171
  subnet_mask: subnet_mask,
171
- subnet_bitmask: subnet_mask.split('.').map \
172
- {|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)},
173
173
  prefix: prefix,
174
174
  subnets: subnets,
175
175
  range: "%s-%s" % [first_ip, last_ip],
@@ -216,7 +216,7 @@ Subnet calculator
216
216
 
217
217
  Inputs:
218
218
 
219
- #{Kvx.new(@inputs).to_s.lines.map {|x| ' ' * 2 + x}.join}
219
+ #{indent Kvx.new(@inputs).to_s}
220
220
 
221
221
  Summary
222
222
  -------
@@ -286,9 +286,9 @@ EOF
286
286
  class_subnets(n, block_size) do |network, first, last, broadcast|
287
287
 
288
288
  {
289
- network: [network, 0].join('.'),
290
- first: [network, 1].join('.'),
291
- last: [broadcast, 254].join('.'),
289
+ network: [network, 0].join('.'),
290
+ first: [network, 1].join('.'),
291
+ last: [broadcast, 254].join('.'),
292
292
  broadcast: [broadcast, 255].join('.')
293
293
  }
294
294
 
@@ -301,15 +301,15 @@ EOF
301
301
  class_subnets(n, block_size) do |network, first, last, broadcast|
302
302
 
303
303
  {
304
- network: [network, 0, 0].join('.'),
305
- first: [network, 1, 1].join('.'),
306
- last: [broadcast, 255, 254].join('.'),
304
+ network: [network, 0, 0].join('.'),
305
+ first: [network, 1, 1].join('.'),
306
+ last: [broadcast, 255, 254].join('.'),
307
307
  broadcast: [broadcast, 255, 255].join('.')
308
308
  }
309
309
 
310
310
  end
311
311
 
312
- end
312
+ end
313
313
 
314
314
  def indent(s, i=2)
315
315
  s.lines.map{|x| ' ' * i + x}.join
data.tar.gz.sig CHANGED
Binary file
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.0
4
+ version: 0.3.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - James Robertson
@@ -10,28 +10,32 @@ bindir: bin
10
10
  cert_chain:
11
11
  - |
12
12
  -----BEGIN CERTIFICATE-----
13
- MIIDljCCAn6gAwIBAgIBATANBgkqhkiG9w0BAQUFADBIMRIwEAYDVQQDDAlnZW1t
14
- YXN0ZXIxHjA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f7
26
+ AS5e9WbqKzpvmILIWCEwJgYDVR0RBB8wHYEbZ2VtbWFzdGVyQGphbWVzcm9iZXJ0
27
+ c29uLmV1MCYGA1UdEgQfMB2BG2dlbW1hc3RlckBqYW1lc3JvYmVydHNvbi5ldTAN
28
+ BgkqhkiG9w0BAQsFAAOCAYEAmczOo8IIS5BJC2SS6fxhxaln1Ws4QofL08hkCGyP
29
+ 9ZbuhqQhcFuB2EQRS8mQDDdHwyWfOalfGWbhPediwgq2tnWzUFRQ6PXSmoUieOYE
30
+ NLsVVnMNbxeDautTXFAW1lvBWkd8CWRehhOqFiZHJb4s1QH15CFZKPNRloqSjlZQ
31
+ uw4dVxUH1tKCsisyl6a0XZpeamGIgWCAK9Xf8PZ6ORvZVL/kaGuZ/6p1DDacSFNE
32
+ uysHzUZIgbUALxG5sDsjn2kI3euWGRpLIzZlaDf3HcQek9vQ63FJoWzI5VoBi1Hb
33
+ /z4Jjtx+hvz/sJfVX2bRYZZBfUy7k8jfUIr2qHVjGAwXXeRdihW+TYwUjzUnfH3r
34
+ z03A25tBmUnyj8bCggtTOJLr1NyoGU2UUyNymVmH+KV5nxyd7AaaFJgUdeJlArwC
35
+ Xvl3mk0+I701FZKkOutz4RhfV+0riwGfBE+vMHNLeZBgGbk1+zwzbeDuEbfOE16i
36
+ yGY4SKyxeL2j6jkB02U8c2FF
33
37
  -----END CERTIFICATE-----
34
- date: 2016-11-07 00:00:00.000000000 Z
38
+ date: 2022-01-26 00:00:00.000000000 Z
35
39
  dependencies:
36
40
  - !ruby/object:Gem::Dependency
37
41
  name: kvx
@@ -39,42 +43,42 @@ dependencies:
39
43
  requirements:
40
44
  - - "~>"
41
45
  - !ruby/object:Gem::Version
42
- version: '0.6'
46
+ version: '1.0'
43
47
  - - ">="
44
48
  - !ruby/object:Gem::Version
45
- version: 0.6.1
49
+ version: 1.0.1
46
50
  type: :runtime
47
51
  prerelease: false
48
52
  version_requirements: !ruby/object:Gem::Requirement
49
53
  requirements:
50
54
  - - "~>"
51
55
  - !ruby/object:Gem::Version
52
- version: '0.6'
56
+ version: '1.0'
53
57
  - - ">="
54
58
  - !ruby/object:Gem::Version
55
- version: 0.6.1
59
+ version: 1.0.1
56
60
  - !ruby/object:Gem::Dependency
57
61
  name: table-formatter
58
62
  requirement: !ruby/object:Gem::Requirement
59
63
  requirements:
60
- - - "~>"
61
- - !ruby/object:Gem::Version
62
- version: '0.4'
63
64
  - - ">="
64
65
  - !ruby/object:Gem::Version
65
66
  version: 0.4.0
67
+ - - "~>"
68
+ - !ruby/object:Gem::Version
69
+ version: '0.4'
66
70
  type: :runtime
67
71
  prerelease: false
68
72
  version_requirements: !ruby/object:Gem::Requirement
69
73
  requirements:
70
- - - "~>"
71
- - !ruby/object:Gem::Version
72
- version: '0.4'
73
74
  - - ">="
74
75
  - !ruby/object:Gem::Version
75
76
  version: 0.4.0
77
+ - - "~>"
78
+ - !ruby/object:Gem::Version
79
+ version: '0.4'
76
80
  description:
77
- email: james@r0bertson.co.uk
81
+ email: digital.robertson@gmail.com
78
82
  executables: []
79
83
  extensions: []
80
84
  extra_rdoc_files: []
@@ -100,7 +104,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
100
104
  version: '0'
101
105
  requirements: []
102
106
  rubyforge_project:
103
- rubygems_version: 2.5.1
107
+ rubygems_version: 2.7.10
104
108
  signing_key:
105
109
  specification_version: 4
106
110
  summary: A subnet calculator (only tested for class C and class B networks)
metadata.gz.sig CHANGED
Binary file