subnetica 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (6) hide show
  1. checksums.yaml +7 -0
  2. data/LICENSE +11 -0
  3. data/README.md +3 -0
  4. data/bin/subnetica +42 -0
  5. data/lib/subnetica.rb +129 -0
  6. metadata +73 -0
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 5b2ca2e2d0b21d4215a8ca9636a36fe3228e4dfa80300c83add93df140d47947
4
+ data.tar.gz: 18fde891686ff4430e109d5f7d7aa834bb016b0f682baaaab92d2735628ddf3d
5
+ SHA512:
6
+ metadata.gz: 9ed8ddc0891e8767a080656d65dc3138fc35b37adc650c783de5095ad5bfc308720ed60f1645cfa0fae62a4f16930b66d890fa037a29c01b17cd36a9f5f26cf9
7
+ data.tar.gz: 0cade32452264e2c2d8183f2f2b6b04fdbb99f34db60c12f03eea1a073a58dd3f107e3d3a15fe72227573a05ff8ccabb5b22d0c07a58924227c45a5fbb4345a0
data/LICENSE ADDED
@@ -0,0 +1,11 @@
1
+ DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
2
+ Version 2, December 2004
3
+
4
+ Copyright (C) 2004 Sam Hocevar <sam@hocevar.net>
5
+
6
+ Everyone is permitted to copy and distribute verbatim or modified copies of this license document, and changing it is allowed as long as the name is changed.
7
+
8
+ DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
9
+ TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
10
+
11
+ 0. You just DO WHAT THE FUCK YOU WANT TO.
data/README.md ADDED
@@ -0,0 +1,3 @@
1
+ # subnetcalc
2
+
3
+ Program that can display IPv4 and IPv6 address information like Network, Netmask, rDNS address and Host Range.
data/bin/subnetica ADDED
@@ -0,0 +1,42 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'ipaddr'
4
+ require 'subnetica'
5
+
6
+ if ARGV.length != 1
7
+ puts 'Usage: subnetica [ip address]'
8
+ exit!
9
+ end
10
+
11
+ ipaddr_str = ARGV[0].dup
12
+ ipaddr_str.strip!
13
+
14
+ begin
15
+ ipaddr = IPAddr.new ipaddr_str
16
+ rescue IPAddr::InvalidAddressError
17
+ puts 'Invalid address'
18
+ exit!
19
+ end
20
+
21
+ attributes, flags = Subnetica.getinfo ipaddr
22
+
23
+ max_len = 0
24
+ attributes.each_key do |key|
25
+ max_len = key.length if key.length > max_len
26
+ end
27
+
28
+ length = max_len + 1
29
+ attributes.each_pair do |key, value|
30
+ puts "#{key}#{' ' * (length - key.length)}= #{value}"
31
+ end
32
+
33
+ puts "Properties#{' ' * (length - 10)}="
34
+ flags.each do |flag|
35
+ if flag.is_a? Array
36
+ flag.each do |sub_flag|
37
+ puts "\t\t+ #{sub_flag}"
38
+ end
39
+ else
40
+ puts "\t- #{flag}"
41
+ end
42
+ end
data/lib/subnetica.rb ADDED
@@ -0,0 +1,129 @@
1
+
2
+ module Subnetica
3
+
4
+ require 'ipaddr'
5
+ require 'meshname'
6
+
7
+ ADDRESSES_4 = [
8
+ [IPAddr.new('0.0.0.0/8'), 'Current network'],
9
+ [IPAddr.new('10.0.0.0/8'), 'Private address'],
10
+ [IPAddr.new('100.64.0.0/10'), 'CG-NAT'],
11
+ [IPAddr.new('127.0.0.0/8'), 'Loopback address'],
12
+ [IPAddr.new('169.254.0.0/16'), 'Link-local address'],
13
+ [IPAddr.new('172.16.0.0/12'), 'Private address'],
14
+ [IPAddr.new('192.0.0.0/24'), 'IETF Protocol Assignments'],
15
+ [IPAddr.new('192.0.2.0/24'), 'TEST-NET-1 (Documentation prefix)'],
16
+ [IPAddr.new('192.88.99.0/24'), 'Reserved'],
17
+ [IPAddr.new('192.168.0.0/16'), 'Private address'],
18
+ [IPAddr.new('198.18.0.0/15'), 'benchmark testing of inter-network communication'],
19
+ [IPAddr.new('198.51.100.0/24'), 'TEST-NET-2 (Documentation prefix)'],
20
+ [IPAddr.new('203.0.113.0/24'), 'TEST-NET-3 (Documentation prefix)'],
21
+ [IPAddr.new('224.0.0.0/4'), 'Multicast address'],
22
+ [IPAddr.new('233.252.0.0/24'), 'MCAST-TEST-NET (Documentation prefix)'],
23
+ [IPAddr.new('240.0.0.0/4'), 'Reserved for future use'],
24
+ [IPAddr.new('255.255.255.255/32'), 'Limited broadcast']
25
+ ].freeze
26
+
27
+ ADDRESSES_6 = [
28
+ [IPAddr.new('::/96'), 'IPv4-mapped'],
29
+ [IPAddr.new('::/128'), 'Unspecified address'],
30
+ [IPAddr.new('::1/128'), 'Loopback address'],
31
+ [IPAddr.new('::ffff:0:0/96'), 'IPv4-mapped addresses'],
32
+ [IPAddr.new('::ffff:0:0:0/96'), 'IPv4 translated addresses'],
33
+ [IPAddr.new('64:ff9b::/96'), 'IPv4/IPv6 translation (RFC6052)'],
34
+ [IPAddr.new('64:ff9b:1::/48'), 'IPv4/IPv6 translation (RFC8215)'],
35
+ [IPAddr.new('100::/64'), 'Discard prefix (RFC6666)'],
36
+ [IPAddr.new('2000::/3'), 'Global Unicast Address (GUA)'],
37
+ [IPAddr.new('2001::/32'), 'Teredo tunneling'],
38
+ [IPAddr.new('2001:20::/28'), 'ORCHIDv2'],
39
+ [IPAddr.new('2001:db8::/32'), 'Documentation prefix (RFC3849)'],
40
+ [IPAddr.new('2002::/16'), '6to4 (deprecated)'],
41
+ [IPAddr.new('fc00::/7'), 'Unique local address (ULA)'],
42
+ [IPAddr.new('fe80::/10'), 'Link-local address'],
43
+ [IPAddr.new('ff00::/8'), 'Multicast address'],
44
+ [IPAddr.new('ff02::1:ff00:0/104'), 'Solicited-node multicast address'],
45
+ [IPAddr.new('ff02::2:ff00:0/104'), 'Node information queries'],
46
+
47
+ [IPAddr.new('ff01::1/128'), 'All nodes in the interface-local'],
48
+ [IPAddr.new('ff02::1/128'), 'All nodes in the link-local'],
49
+ [IPAddr.new('ff01::2/128'), 'All routers in the interface-local'],
50
+ [IPAddr.new('ff02::2/128'), 'All routers in the link-local'],
51
+ [IPAddr.new('ff05::2/128'), 'All routers in the site-local'],
52
+ [IPAddr.new('ff02::5/128'), 'OSPF'],
53
+ [IPAddr.new('ff02::6/128'), 'OSPF'],
54
+ [IPAddr.new('ff02::9/128'), 'RIP'],
55
+ [IPAddr.new('ff02::a/128'), 'EIGRP'],
56
+ [IPAddr.new('ff02::d/128'), 'RPL'],
57
+ [IPAddr.new('ff01::fb/128'), 'mDNSv6 in the interface-local'],
58
+ [IPAddr.new('ff02::fb/128'), 'mDNSv6 in the link-local'],
59
+ [IPAddr.new('ff03::fb/128'), 'mDNSv6 in the realm-local'],
60
+ [IPAddr.new('ff04::fb/128'), 'mDNSv6 in the admin-local'],
61
+ [IPAddr.new('ff05::fb/128'), 'mDNSv6 in the site-local'],
62
+ [IPAddr.new('ff08::fb/128'), 'mDNSv6 in the organization-local'],
63
+ [IPAddr.new('ff0e::fb/128'), 'mDNSv6 in the global'],
64
+ [IPAddr.new('ff01::101/128'), 'All NTP servers in the interface-local'],
65
+ [IPAddr.new('ff02::101/128'), 'All NTP servers in the link-local'],
66
+ [IPAddr.new('ff03::101/128'), 'All NTP servers in the realm-local'],
67
+ [IPAddr.new('ff04::101/128'), 'All NTP servers in the admin-local'],
68
+ [IPAddr.new('ff05::101/128'), 'All NTP servers in the site-local'],
69
+ [IPAddr.new('ff08::101/128'), 'All NTP servers in the organization-local'],
70
+ [IPAddr.new('ff0e::101/128'), 'All NTP servers in the global'],
71
+ [IPAddr.new('ff02::1:1/128'), 'Link name'],
72
+ [IPAddr.new('ff02::1:2/128'), 'All-dhcp-agents (DHCPv6) in the link-local'],
73
+ [IPAddr.new('ff02::1:3/128'), 'Link-local multicast name resolution'],
74
+ [IPAddr.new('ff05::1:3/128'), 'All-dhcp-agents (DHCPv6) in the site-local']
75
+ ].freeze
76
+
77
+ def self.getinfo ipaddr
78
+ raise ArgumentError, 'IP address must be of type IPAddr' if ! ipaddr.is_a? IPAddr
79
+
80
+ flags = []
81
+ attributes = {}
82
+
83
+ attributes['Address'] = ipaddr
84
+ attributes['Network'] = "#{ipaddr.mask(ipaddr.prefix)} / #{ipaddr.prefix}"
85
+ attributes['Netmask'] = ipaddr.netmask
86
+
87
+ if ipaddr.ipv4?
88
+ flags << 'IPv4'
89
+
90
+ ADDRESSES_4.each do |ip, descr|
91
+ flags << descr if ip.include? ipaddr
92
+ end
93
+
94
+ attributes['IPv4-mapped IPv6'] = "::ffff:#{ipaddr}"
95
+ elsif ipaddr.ipv6?
96
+ flags << 'IPv6'
97
+
98
+ if ipaddr.ipv4_mapped?
99
+ attributes['IPv4'] = ipaddr.native
100
+ attributes['Alternative address'] = ":#{ipaddr.inspect[39...-41]}"
101
+ end
102
+
103
+ attributes['Meshname'] = "#{Meshname.getname ipaddr}.meship"
104
+
105
+ [128, 64, 56, 48].each do |mask|
106
+ bits = mask - ipaddr.prefix
107
+ if bits.positive?
108
+ num_prefix = 2**bits
109
+ calc_res = " = #{num_prefix}" if num_prefix <= 65_536
110
+ attributes["/#{mask}s"] = "2^#{bits}#{calc_res}"
111
+ end
112
+ end
113
+
114
+ ADDRESSES_6.each do |ip, descr|
115
+ flags << descr if ip.include? ipaddr
116
+ end
117
+ else
118
+ flags << 'Unknown IP version'
119
+ end
120
+
121
+ attributes['rDNS'] = ipaddr.reverse
122
+
123
+ range = ipaddr.to_range
124
+ attributes['Host Range'] = "{ #{range.first} - #{range.last} }"
125
+
126
+ return [attributes, flags]
127
+ end
128
+
129
+ end
metadata ADDED
@@ -0,0 +1,73 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: subnetica
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ platform: ruby
6
+ authors:
7
+ - Marek Küthe
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2023-04-20 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: base32
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '0.3'
20
+ - - ">="
21
+ - !ruby/object:Gem::Version
22
+ version: 0.3.4
23
+ type: :runtime
24
+ prerelease: false
25
+ version_requirements: !ruby/object:Gem::Requirement
26
+ requirements:
27
+ - - "~>"
28
+ - !ruby/object:Gem::Version
29
+ version: '0.3'
30
+ - - ">="
31
+ - !ruby/object:Gem::Version
32
+ version: 0.3.4
33
+ description: Program that can display IPv4 and IPv6 address information like Network,
34
+ Netmask, rDNS address and Host Range.
35
+ email: m.k@mk16.de
36
+ executables:
37
+ - subnetica
38
+ extensions: []
39
+ extra_rdoc_files:
40
+ - LICENSE
41
+ - README.md
42
+ files:
43
+ - LICENSE
44
+ - README.md
45
+ - bin/subnetica
46
+ - lib/subnetica.rb
47
+ homepage: https://codeberg.org/mark22k/subnetica
48
+ licenses:
49
+ - WTFPL
50
+ metadata:
51
+ source_code_uri: https://codeberg.org/mark22k/subnetica
52
+ bug_tracker_uri: https://codeberg.org/mark22k/subnetica/issues
53
+ rubygems_mfa_required: 'true'
54
+ post_install_message:
55
+ rdoc_options: []
56
+ require_paths:
57
+ - lib
58
+ required_ruby_version: !ruby/object:Gem::Requirement
59
+ requirements:
60
+ - - ">="
61
+ - !ruby/object:Gem::Version
62
+ version: '3.1'
63
+ required_rubygems_version: !ruby/object:Gem::Requirement
64
+ requirements:
65
+ - - ">="
66
+ - !ruby/object:Gem::Version
67
+ version: '0'
68
+ requirements: []
69
+ rubygems_version: 3.4.12
70
+ signing_key:
71
+ specification_version: 4
72
+ summary: Program that can display IPv4 and IPv6 address information.
73
+ test_files: []