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 +5 -5
- checksums.yaml.gz.sig +0 -0
- data/lib/subnet_calc.rb +17 -17
- data.tar.gz.sig +0 -0
- metadata +38 -34
- metadata.gz.sig +0 -0
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 704ba733fc18df391c8e1c226a80d6b4211afdbb859038be24a8b1b79da15dfd
|
4
|
+
data.tar.gz: bb2c85e9364aa9503a5b8c299967e87f8a384c9dbc03f0ae0330989f82dbc152
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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
|
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:
|
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,
|
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[
|
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..
|
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
|
-
|
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
|
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
|
-
|
290
|
-
|
291
|
-
|
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
|
-
|
305
|
-
|
306
|
-
|
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.
|
4
|
+
version: 0.3.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- James Robertson
|
@@ -10,28 +10,32 @@ bindir: bin
|
|
10
10
|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g6cS3mWnuAf92Kjg0c1tPUCAwEA
|
25
|
+
AaOBijCBhzAJBgNVHRMEAjAAMAsGA1UdDwQEAwIEsDAdBgNVHQ4EFgQULNuL6xf7
|
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:
|
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
|
46
|
+
version: '1.0'
|
43
47
|
- - ">="
|
44
48
|
- !ruby/object:Gem::Version
|
45
|
-
version: 0.
|
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
|
56
|
+
version: '1.0'
|
53
57
|
- - ">="
|
54
58
|
- !ruby/object:Gem::Version
|
55
|
-
version: 0.
|
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:
|
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.
|
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
|