iana-data 1.2.0 → 1.2.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.gitignore +2 -0
- data/Gemfile.lock +1 -1
- data/README.md +2 -1
- data/Rakefile +0 -24
- data/lib/iana.rb +0 -7
- data/lib/iana/port.rb +6 -5
- data/lib/iana/protocol.rb +6 -9
- data/lib/iana/version.rb +1 -1
- metadata +2 -5
- data/examples/ethertypes.rb +0 -51
- data/iana.tmproj +0 -49
- data/lib/iana/ethertype.rb +0 -99
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA1:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: d5fdb0b10d3112feec02cc89426839715ed65557
|
|
4
|
+
data.tar.gz: 8467afe37c36ad8e04accab7c8060a9462ef8968
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: ac75ad3a2e515b8f5a950bfaddc9f8154128bd2182ff2f30393b88388dd9e8cb181e72ccecd379988a4280471d21fc1381fd1ff5ecc7d4758d44853af5ae29ca
|
|
7
|
+
data.tar.gz: 2ab92e0cd29d5bd38ec5a1a19ff58a86f4c8da87fb321422bd2d9b18c7b7c09f39042fb0ebe688ae61f37d20be66016e43a1bcd8457b6544f8766389e83be12a
|
data/.gitignore
CHANGED
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
## What
|
|
2
|
-
IANA Ruby module
|
|
2
|
+
IANA Ruby module [](https://badge.fury.io/rb/iana-data)
|
|
3
|
+
[](https://codeclimate.com/github/ringe/iana)
|
|
3
4
|
|
|
4
5
|
Look up TCP/IP port numbers, protocols, top-level domains, et al.
|
|
5
6
|
|
data/Rakefile
CHANGED
|
@@ -30,27 +30,3 @@ Rake::TestTask.new do |t|
|
|
|
30
30
|
t.test_files = FileList['test/*.rb']
|
|
31
31
|
t.verbose = true
|
|
32
32
|
end
|
|
33
|
-
|
|
34
|
-
desc 'count source lines of code'
|
|
35
|
-
task :count do
|
|
36
|
-
system('cloc lib')
|
|
37
|
-
end
|
|
38
|
-
|
|
39
|
-
namespace :todo do
|
|
40
|
-
desc 'List TODOs in all .rb files under lib/'
|
|
41
|
-
task(:list) do
|
|
42
|
-
FileList["lib/**/*.rb", "bin/**/*.rb"].egrep(/TODO/)
|
|
43
|
-
end
|
|
44
|
-
|
|
45
|
-
desc 'Edit all TODOs in VIM' # or your favorite editor
|
|
46
|
-
task(:edit) do
|
|
47
|
-
# jump to the first TODO in the first file
|
|
48
|
-
cmd = 'vim +/TODO/'
|
|
49
|
-
|
|
50
|
-
filelist = []
|
|
51
|
-
FileList["lib/**/*.rb"].egrep(/TODO/) { |fn,cnt,line| filelist << fn }
|
|
52
|
-
|
|
53
|
-
# will fork a new process and exit, if you're using gvim
|
|
54
|
-
system("#{cmd} #{filelist.sort.join(' ')}")
|
|
55
|
-
end
|
|
56
|
-
end
|
data/lib/iana.rb
CHANGED
|
@@ -9,16 +9,9 @@ end # IANA
|
|
|
9
9
|
require 'open-uri'
|
|
10
10
|
require 'open-uri/cached'
|
|
11
11
|
|
|
12
|
-
#require 'consumer'
|
|
13
|
-
require 'iana/ethertype'
|
|
14
12
|
require 'iana/port'
|
|
15
13
|
require 'iana/protocol'
|
|
16
14
|
require 'iana/tld'
|
|
17
15
|
require 'iana/lsr'
|
|
18
16
|
|
|
19
|
-
# TODO implement consumer model
|
|
20
|
-
# TODO complete documentaion
|
|
21
|
-
# TODO implement unit tests
|
|
22
|
-
# TODO lookup needs to be more flexible
|
|
23
|
-
|
|
24
17
|
raise RuntimeError, 'This library is for require only' if $0 == __FILE__
|
data/lib/iana/port.rb
CHANGED
|
@@ -6,6 +6,8 @@
|
|
|
6
6
|
|
|
7
7
|
module IANA
|
|
8
8
|
class Port
|
|
9
|
+
SOURCE = "http://www.iana.org/assignments/service-names-port-numbers/service-names-port-numbers.csv"
|
|
10
|
+
|
|
9
11
|
attr_reader :port, :keyword, :protocol, :description
|
|
10
12
|
|
|
11
13
|
def initialize(port, keyword, protocol, description)
|
|
@@ -18,17 +20,16 @@ module IANA
|
|
|
18
20
|
def protocol; @protocol; end
|
|
19
21
|
def description; @description; end
|
|
20
22
|
|
|
23
|
+
def self.source
|
|
24
|
+
@source ||= open(SOURCE).read
|
|
25
|
+
end
|
|
26
|
+
|
|
21
27
|
# Download IANA ports list in XML format, return list
|
|
22
28
|
# http://www.iana.org/assignments/service-names-port-numbers/service-names-port-numbers.xml
|
|
23
29
|
def self.iana_list
|
|
24
|
-
source = open("http://www.iana.org/assignments/service-names-port-numbers/service-names-port-numbers.csv").
|
|
25
|
-
read
|
|
26
|
-
|
|
27
30
|
# concatenate multiline strings, then split on newline
|
|
28
31
|
lines = source.gsub(/(?<!\r)\n/, ' ').split(/\r\n/)
|
|
29
|
-
|
|
30
32
|
ports = {}
|
|
31
|
-
|
|
32
33
|
begin
|
|
33
34
|
while (line = lines.shift)
|
|
34
35
|
# skip lines which do not contain the ,proto, pattern
|
data/lib/iana/protocol.rb
CHANGED
|
@@ -9,6 +9,8 @@ require 'nokogiri'
|
|
|
9
9
|
|
|
10
10
|
module IANA
|
|
11
11
|
class Protocol
|
|
12
|
+
SOURCE = "http://www.iana.org/assignments/protocol-numbers/protocol-numbers.xml"
|
|
13
|
+
|
|
12
14
|
attr_reader :protocol, :name, :description, :references
|
|
13
15
|
|
|
14
16
|
def initialize(protocol, name, description, xref)
|
|
@@ -21,19 +23,17 @@ module IANA
|
|
|
21
23
|
def description; @description; end
|
|
22
24
|
def references; @references; end
|
|
23
25
|
|
|
26
|
+
def self.source
|
|
27
|
+
@source ||= open(SOURCE).read
|
|
28
|
+
end
|
|
29
|
+
|
|
24
30
|
# Download IANA protocols list in XML format, return list
|
|
25
31
|
# http://www.iana.org/assignments/protocol-numbers/protocol-numbers.xml
|
|
26
32
|
def self.iana_list
|
|
27
|
-
source = open("http://www.iana.org/assignments/protocol-numbers/protocol-numbers.xml").read
|
|
28
|
-
|
|
29
33
|
protocols = {}
|
|
30
|
-
updated = nil
|
|
31
|
-
|
|
32
34
|
begin
|
|
33
35
|
doc = Nokogiri::XML(source)
|
|
34
|
-
updated = doc.css('registry/updated').text
|
|
35
36
|
doc.css('registry/registry/record').each do |r|
|
|
36
|
-
# range
|
|
37
37
|
value = r.css('value').text
|
|
38
38
|
if value =~ /-/ then
|
|
39
39
|
low,high = value.split('-').map(&:to_i)
|
|
@@ -42,11 +42,9 @@ module IANA
|
|
|
42
42
|
high = low
|
|
43
43
|
end
|
|
44
44
|
|
|
45
|
-
# name
|
|
46
45
|
name = r.css('name').text
|
|
47
46
|
name = nil if !name.nil? && name.empty?
|
|
48
47
|
|
|
49
|
-
# description
|
|
50
48
|
description = r.css('description').text
|
|
51
49
|
description = nil if !description.nil? && description.empty?
|
|
52
50
|
|
|
@@ -67,7 +65,6 @@ module IANA
|
|
|
67
65
|
end
|
|
68
66
|
end
|
|
69
67
|
end
|
|
70
|
-
|
|
71
68
|
return protocols
|
|
72
69
|
end
|
|
73
70
|
|
data/lib/iana/version.rb
CHANGED
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: iana-data
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 1.2.
|
|
4
|
+
version: 1.2.1
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Runar Ingebrigtsen
|
|
@@ -9,7 +9,7 @@ authors:
|
|
|
9
9
|
autorequire:
|
|
10
10
|
bindir: exe
|
|
11
11
|
cert_chain: []
|
|
12
|
-
date: 2016-04-
|
|
12
|
+
date: 2016-04-26 00:00:00.000000000 Z
|
|
13
13
|
dependencies:
|
|
14
14
|
- !ruby/object:Gem::Dependency
|
|
15
15
|
name: bundler
|
|
@@ -113,14 +113,11 @@ files:
|
|
|
113
113
|
- bin/console
|
|
114
114
|
- bin/setup
|
|
115
115
|
- example-data/lsr.txt
|
|
116
|
-
- examples/ethertypes.rb
|
|
117
116
|
- examples/ports.rb
|
|
118
117
|
- examples/protocols.rb
|
|
119
118
|
- examples/tlds.rb
|
|
120
119
|
- iana.gemspec
|
|
121
|
-
- iana.tmproj
|
|
122
120
|
- lib/iana.rb
|
|
123
|
-
- lib/iana/ethertype.rb
|
|
124
121
|
- lib/iana/lsr.rb
|
|
125
122
|
- lib/iana/port.rb
|
|
126
123
|
- lib/iana/protocol.rb
|
data/examples/ethertypes.rb
DELETED
|
@@ -1,51 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env ruby
|
|
2
|
-
# encoding: UTF-8
|
|
3
|
-
# vim: expandtab tabstop=2 softtabstop=2 shiftwidth=2
|
|
4
|
-
|
|
5
|
-
# examples/ethertypes.rb
|
|
6
|
-
|
|
7
|
-
require 'pathname'
|
|
8
|
-
dir = Pathname.new(File.expand_path(__FILE__)).realpath
|
|
9
|
-
require File.join(File.dirname(dir.to_s), '../lib/iana')
|
|
10
|
-
|
|
11
|
-
SCRIPT = File.basename(__FILE__)
|
|
12
|
-
|
|
13
|
-
def known_ethertype?(ethertype)
|
|
14
|
-
|
|
15
|
-
IANA_ETHERTYPES.include?(ethertype)
|
|
16
|
-
end
|
|
17
|
-
|
|
18
|
-
if ARGV.length == 1
|
|
19
|
-
begin
|
|
20
|
-
IANA_ETHERTYPES, IANA_ETHERTYPES_UPDATED = IANA::EtherType::load(ARGV[0])
|
|
21
|
-
rescue
|
|
22
|
-
puts "#{SCRIPT}: #{$!}"
|
|
23
|
-
exit 1
|
|
24
|
-
end
|
|
25
|
-
else
|
|
26
|
-
puts "Usage: #{SCRIPT} <ethernet-numbers>"
|
|
27
|
-
exit 1
|
|
28
|
-
end
|
|
29
|
-
|
|
30
|
-
puts "updated #{IANA_ETHERTYPES_UPDATED} => #{IANA_ETHERTYPES.size} entries"
|
|
31
|
-
puts
|
|
32
|
-
IANA_ETHERTYPES.each do |t|
|
|
33
|
-
print "#{t.begin}"
|
|
34
|
-
print "-#{t.end}" if t.end != t.begin
|
|
35
|
-
puts " => #{t.description}"
|
|
36
|
-
end
|
|
37
|
-
puts
|
|
38
|
-
|
|
39
|
-
# known in :begin => true
|
|
40
|
-
puts "86dd is known? => #{IANA::EtherType.known?("86dd")}"
|
|
41
|
-
|
|
42
|
-
# known in :end => true
|
|
43
|
-
puts "8a97 is known? => #{IANA::EtherType.known?("8a97")}"
|
|
44
|
-
|
|
45
|
-
# known between :begin and :end => true
|
|
46
|
-
puts "8709 is known? => #{IANA::EtherType.known?("8709")}"
|
|
47
|
-
|
|
48
|
-
# unknown => false
|
|
49
|
-
puts "fefe is known? => #{IANA::EtherType.known?("fefe")}"
|
|
50
|
-
|
|
51
|
-
exit 0
|
data/iana.tmproj
DELETED
|
@@ -1,49 +0,0 @@
|
|
|
1
|
-
<?xml version="1.0" encoding="UTF-8"?>
|
|
2
|
-
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
|
|
3
|
-
<plist version="1.0">
|
|
4
|
-
<dict>
|
|
5
|
-
<key>documents</key>
|
|
6
|
-
<array>
|
|
7
|
-
<dict>
|
|
8
|
-
<key>filename</key>
|
|
9
|
-
<string>README</string>
|
|
10
|
-
</dict>
|
|
11
|
-
<dict>
|
|
12
|
-
<key>filename</key>
|
|
13
|
-
<string>LICENSE</string>
|
|
14
|
-
</dict>
|
|
15
|
-
<dict>
|
|
16
|
-
<key>filename</key>
|
|
17
|
-
<string>Rakefile</string>
|
|
18
|
-
</dict>
|
|
19
|
-
<dict>
|
|
20
|
-
<key>expanded</key>
|
|
21
|
-
<true/>
|
|
22
|
-
<key>name</key>
|
|
23
|
-
<string>lib</string>
|
|
24
|
-
<key>regexFolderFilter</key>
|
|
25
|
-
<string>!.*/(\.[^/]*|CVS|_darcs|_MTN|\{arch\}|blib|.*~\.nib|.*\.(framework|app|pbproj|pbxproj|xcode(proj)?|bundle))$</string>
|
|
26
|
-
<key>sourceDirectory</key>
|
|
27
|
-
<string>lib</string>
|
|
28
|
-
</dict>
|
|
29
|
-
<dict>
|
|
30
|
-
<key>expanded</key>
|
|
31
|
-
<true/>
|
|
32
|
-
<key>name</key>
|
|
33
|
-
<string>examples</string>
|
|
34
|
-
<key>regexFolderFilter</key>
|
|
35
|
-
<string>!.*/(\.[^/]*|CVS|_darcs|_MTN|\{arch\}|blib|.*~\.nib|.*\.(framework|app|pbproj|pbxproj|xcode(proj)?|bundle))$</string>
|
|
36
|
-
<key>sourceDirectory</key>
|
|
37
|
-
<string>examples</string>
|
|
38
|
-
</dict>
|
|
39
|
-
</array>
|
|
40
|
-
<key>fileHierarchyDrawerWidth</key>
|
|
41
|
-
<integer>200</integer>
|
|
42
|
-
<key>metaData</key>
|
|
43
|
-
<dict/>
|
|
44
|
-
<key>showFileHierarchyDrawer</key>
|
|
45
|
-
<true/>
|
|
46
|
-
<key>windowFrame</key>
|
|
47
|
-
<string>{{638, 167}, {728, 637}}</string>
|
|
48
|
-
</dict>
|
|
49
|
-
</plist>
|
data/lib/iana/ethertype.rb
DELETED
|
@@ -1,99 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env ruby
|
|
2
|
-
# encoding: UTF-8
|
|
3
|
-
# vim: expandtab tabstop=2 softtabstop=2 shiftwidth=2
|
|
4
|
-
|
|
5
|
-
# lib/iana/ethertype.rb
|
|
6
|
-
|
|
7
|
-
module IANA
|
|
8
|
-
module EtherType
|
|
9
|
-
EtherType = Struct.new('ETHERTYPE', :begin, :end, :description)
|
|
10
|
-
|
|
11
|
-
# I hate doing it this way, but the inconsistency of IANA data files...
|
|
12
|
-
LAST_ENTRY = '^ 65535 FFFF - - Reserved \[RFC1701\]$'
|
|
13
|
-
|
|
14
|
-
# load IANA Ether types list from flat file:
|
|
15
|
-
# http://www.iana.org/assignments/ethernet-numbers
|
|
16
|
-
def self.load(pathname)
|
|
17
|
-
raise ArgumentError, 'nil pathname' if pathname.nil?
|
|
18
|
-
raise ArgumentError, 'invalid pathname class' if pathname.class != String
|
|
19
|
-
raise ArgumentError, 'empty pathname' if pathname.empty?
|
|
20
|
-
|
|
21
|
-
# TODO: better error checking for files with incorrect content
|
|
22
|
-
|
|
23
|
-
ethertypes = []
|
|
24
|
-
updated = nil
|
|
25
|
-
|
|
26
|
-
begin
|
|
27
|
-
f = File.new(pathname, 'r')
|
|
28
|
-
while (line = f.gets)
|
|
29
|
-
line.chomp!
|
|
30
|
-
|
|
31
|
-
# extract update stamp
|
|
32
|
-
if line =~ /^\(last updated (\d{4}-\d{2}-\d{2})\)\s*$/
|
|
33
|
-
updated = $1
|
|
34
|
-
next
|
|
35
|
-
end
|
|
36
|
-
|
|
37
|
-
# skip lines that don't have [XXX] or (XXX) at the end
|
|
38
|
-
next if line !~ /\[\w*\]$/ && line !~ /\([\w\s]*\)$/
|
|
39
|
-
|
|
40
|
-
# now skip all lines that don't begin with a space
|
|
41
|
-
next if line !~ /^[\t\ ]*/
|
|
42
|
-
|
|
43
|
-
# skip over decimal Ethertype
|
|
44
|
-
pos = 0
|
|
45
|
-
if line =~ /^\t\ /
|
|
46
|
-
pos = 2
|
|
47
|
-
else
|
|
48
|
-
pos = 9
|
|
49
|
-
end
|
|
50
|
-
|
|
51
|
-
# clean up ridiculous IANA formatting
|
|
52
|
-
line.gsub!(/^\t/, '8') # TODO: investigate this weirdness
|
|
53
|
-
line.gsub!(/\t -/, ' -')
|
|
54
|
-
line.gsub!(/\t\t\t /, ' ')
|
|
55
|
-
line.gsub!(/\t/, ' ')
|
|
56
|
-
|
|
57
|
-
tmp = line[pos..-1]
|
|
58
|
-
|
|
59
|
-
ethertype = tmp[0..9].strip!
|
|
60
|
-
low, high = ethertype.split('-')
|
|
61
|
-
high = low if high.nil?
|
|
62
|
-
|
|
63
|
-
description, *junk = tmp[25..-1].split('[')
|
|
64
|
-
description.strip!
|
|
65
|
-
|
|
66
|
-
et = EtherType.new(low, high, description)
|
|
67
|
-
ethertypes << et
|
|
68
|
-
|
|
69
|
-
# short-circuit as soon as we've hit the end of the list
|
|
70
|
-
break if line =~ /#{LAST_ENTRY}/
|
|
71
|
-
end
|
|
72
|
-
ensure
|
|
73
|
-
f.close if !f.nil?
|
|
74
|
-
end
|
|
75
|
-
|
|
76
|
-
return ethertypes, updated
|
|
77
|
-
end
|
|
78
|
-
|
|
79
|
-
# is specified Ether type known
|
|
80
|
-
def self.known?(ethertype)
|
|
81
|
-
raise ArgumentError, 'nil ethertype' if ethertype.nil?
|
|
82
|
-
raise ArgumentError, 'invalid ethertype class' if \
|
|
83
|
-
ethertype.class != String
|
|
84
|
-
raise ArgumentError, 'empty ethertype' if ethertype.empty?
|
|
85
|
-
|
|
86
|
-
IANA_ETHERTYPES.each do |t|
|
|
87
|
-
return true if ethertype.upcase == t.begin
|
|
88
|
-
if t.end != t.begin
|
|
89
|
-
return true if ethertype.upcase >= t.begin && \
|
|
90
|
-
ethertype.upcase <= t.end
|
|
91
|
-
end
|
|
92
|
-
end
|
|
93
|
-
|
|
94
|
-
false
|
|
95
|
-
end
|
|
96
|
-
end
|
|
97
|
-
end
|
|
98
|
-
|
|
99
|
-
raise RuntimeError, 'This library is for require only' if $0 == __FILE__
|