nicinfo 0.2.0

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.
Files changed (47) hide show
  1. checksums.yaml +7 -0
  2. data/bin/nicinfo +22 -0
  3. data/lib/autnum.rb +90 -0
  4. data/lib/bootstrap.rb +198 -0
  5. data/lib/bsfiles/asn.json +2326 -0
  6. data/lib/bsfiles/dns.json +25 -0
  7. data/lib/bsfiles/entity.json +52 -0
  8. data/lib/bsfiles/ipv4.json +244 -0
  9. data/lib/bsfiles/ipv6.json +97 -0
  10. data/lib/cache.rb +141 -0
  11. data/lib/common_json.rb +263 -0
  12. data/lib/common_names.rb +49 -0
  13. data/lib/config.rb +260 -0
  14. data/lib/constants.rb +113 -0
  15. data/lib/data_tree.rb +205 -0
  16. data/lib/demo/autnum.json +228 -0
  17. data/lib/demo/domain-dnr.json +695 -0
  18. data/lib/demo/domain-rir.json +569 -0
  19. data/lib/demo/domains.json +625 -0
  20. data/lib/demo/entities.json +545 -0
  21. data/lib/demo/entity-dnr.json +143 -0
  22. data/lib/demo/entity-rir.json +394 -0
  23. data/lib/demo/error-code.json +31 -0
  24. data/lib/demo/help.json +58 -0
  25. data/lib/demo/ip.json +306 -0
  26. data/lib/demo/nameservers.json +434 -0
  27. data/lib/demo/ns-simple.json +210 -0
  28. data/lib/demo/ns-very-simple.json +41 -0
  29. data/lib/demo/ns.json +63 -0
  30. data/lib/demo/simple-ip.json +41 -0
  31. data/lib/demo/simple.json +13 -0
  32. data/lib/domain.rb +203 -0
  33. data/lib/ds_data.rb +70 -0
  34. data/lib/entity.rb +372 -0
  35. data/lib/enum.rb +47 -0
  36. data/lib/error_code.rb +56 -0
  37. data/lib/female-first-names.txt +4275 -0
  38. data/lib/ip.rb +86 -0
  39. data/lib/key_data.rb +70 -0
  40. data/lib/last-names.txt +88799 -0
  41. data/lib/male-first-names.txt +1219 -0
  42. data/lib/nicinfo_logger.rb +370 -0
  43. data/lib/nicinfo_main.rb +1013 -0
  44. data/lib/notices.rb +110 -0
  45. data/lib/ns.rb +108 -0
  46. data/lib/utils.rb +189 -0
  47. metadata +90 -0
data/lib/notices.rb ADDED
@@ -0,0 +1,110 @@
1
+ # Copyright (C) 2011,2012,2013,2014 American Registry for Internet Numbers
2
+ #
3
+ # Permission to use, copy, modify, and/or distribute this software for any
4
+ # purpose with or without fee is hereby granted, provided that the above
5
+ # copyright notice and this permission notice appear in all copies.
6
+ #
7
+ # THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
8
+ # WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
9
+ # MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
10
+ # ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
11
+ # WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
12
+ # ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR
13
+ # IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
14
+
15
+ require 'config'
16
+ require 'nicinfo_logger'
17
+ require 'utils'
18
+
19
+ module NicInfo
20
+
21
+ # deals with RDAP notices structures
22
+ class Notices
23
+
24
+ def Notices.is_excessive_notice notices, config
25
+ return false if !notices
26
+ return false if notices.length == 0
27
+ return true if notices.length > 2
28
+ word_count = 0
29
+ line_count = 0
30
+ notices.each do |notice|
31
+ descriptions = NicInfo::get_descriptions notice, config
32
+ descriptions.each do |line|
33
+ line_count = line_count + 1
34
+ word_count = word_count + line.length
35
+ end if descriptions and descriptions.instance_of? Array
36
+ end
37
+ return true if line_count > 10
38
+ return true if word_count > 700
39
+ #otherwise
40
+ return false
41
+ end
42
+
43
+ def display_notices json_response, config, ignore_excessive
44
+
45
+ notices = json_response[ "notices" ]
46
+ return if notices == nil
47
+ if (Notices::is_excessive_notice(notices,config) ) && (config.logger.data_amount != NicInfo::DataAmount::EXTRA_DATA) && !ignore_excessive
48
+ config.logger.start_data_item
49
+ config.logger.raw NicInfo::DataAmount::NORMAL_DATA, "Excessive Notices"
50
+ config.logger.raw NicInfo::DataAmount::NORMAL_DATA, "-----------------"
51
+ config.logger.raw NicInfo::DataAmount::NORMAL_DATA, "Response contains excessive notices."
52
+ config.logger.raw NicInfo::DataAmount::NORMAL_DATA, "Use the \"-V\" or \"--data extra\" options to see them."
53
+ config.logger.end_data_item
54
+ else
55
+ notices.each do |notice|
56
+ display_single_notice notice, config
57
+ end
58
+ end
59
+
60
+ end
61
+
62
+ def display_single_notice notice, config
63
+ config.logger.start_data_item
64
+ title = notice[ "title" ]
65
+ if title == nil
66
+ title = ""
67
+ end
68
+ config.conf_msgs << "'title' in 'notice' is not a string." unless title.instance_of?( String )
69
+ config.logger.prose NicInfo::DataAmount::NORMAL_DATA, "[ NOTICE ]", title
70
+ type = notice[ "type" ]
71
+ if type != nil
72
+ config.logger.prose NicInfo::DataAmount::NORMAL_DATA, "Type", NicInfo.capitalize( type )
73
+ end
74
+ description = notice[ "description" ]
75
+ i = 1
76
+ if description.instance_of?( Array )
77
+ description.each do |line|
78
+ if line.instance_of?( String )
79
+ config.logger.prose NicInfo::DataAmount::NORMAL_DATA, i.to_s, line
80
+ i = i + 1
81
+ else
82
+ config.conf_msgs << "eleemnt of 'description' in 'notice' is not a string."
83
+ end
84
+ end
85
+ else
86
+ config.conf_msgs << "'description' in 'notice' is not an array."
87
+ end
88
+ links = notice[ "links" ]
89
+ if links
90
+ if links.instance_of?( Array )
91
+ alternate = NicInfo.get_alternate_link links
92
+ config.logger.prose NicInfo::DataAmount::NORMAL_DATA, "More", alternate if alternate
93
+ about = NicInfo.get_about_link links
94
+ config.logger.prose NicInfo::DataAmount::NORMAL_DATA, "About", about if about
95
+ tos = NicInfo.get_tos_link links
96
+ config.logger.prose NicInfo::DataAmount::NORMAL_DATA, "TOS", tos if tos
97
+ copyright = NicInfo.get_copyright_link links
98
+ config.logger.prose NicInfo::DataAmount::NORMAL_DATA, "(C)", copyright if copyright
99
+ license = NicInfo.get_license_link links
100
+ config.logger.prose NicInfo::DataAmount::NORMAL_DATA, "License", license if license
101
+ else
102
+ config.conf_msgs << "'links' is not an array."
103
+ end
104
+ end
105
+ config.logger.end_data_item
106
+ end
107
+
108
+ end
109
+
110
+ end
data/lib/ns.rb ADDED
@@ -0,0 +1,108 @@
1
+ # Copyright (C) 2011,2012,2013,2014 American Registry for Internet Numbers
2
+ #
3
+ # Permission to use, copy, modify, and/or distribute this software for any
4
+ # purpose with or without fee is hereby granted, provided that the above
5
+ # copyright notice and this permission notice appear in all copies.
6
+ #
7
+ # THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
8
+ # WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
9
+ # MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
10
+ # ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
11
+ # WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
12
+ # ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR
13
+ # IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
14
+
15
+ require 'config'
16
+ require 'nicinfo_logger'
17
+ require 'utils'
18
+ require 'common_json'
19
+ require 'entity'
20
+ require 'data_tree'
21
+
22
+ module NicInfo
23
+
24
+ def NicInfo.display_ns json_data, config, data_node
25
+ ns = Ns.new( config ).process( json_data )
26
+ NicInfo::display_object_with_entities( ns, config, data_node )
27
+ end
28
+
29
+ def NicInfo.display_nameservers json_data, config, data_node
30
+ ns_array = json_data[ "nameserverSearchResults" ]
31
+ if ns_array != nil
32
+ if ns_array.instance_of? Array
33
+ display_array = Array.new
34
+ ns_array.each do |ea|
35
+ ns = Ns.new( config ).process( ea )
36
+ display_array << ns
37
+ end
38
+ NicInfo::display_object_with_entities( display_array, config, data_node )
39
+ else
40
+ config.conf_msgs << "'nameserverSearchResults' is not an array"
41
+ end
42
+ else
43
+ config.conf_msgs << "'nameserverSearchResults' is not present"
44
+ end
45
+ end
46
+
47
+ # deals with RDAP nameserver structures
48
+ class Ns
49
+
50
+ attr_accessor :entities, :objectclass, :asEventActors
51
+
52
+ def initialize config
53
+ @config = config
54
+ @common = CommonJson.new config
55
+ @entities = Array.new
56
+ @asEventActors = Array.new
57
+ end
58
+
59
+ def process json_data
60
+ @objectclass = json_data
61
+ @entities = @common.process_entities @objectclass
62
+ return self
63
+ end
64
+
65
+ def display
66
+ @config.logger.start_data_item
67
+ @config.logger.data_title "[ NAME SERVER ]"
68
+ @config.logger.terse "Handle", NicInfo::get_handle( @objectclass )
69
+ @config.logger.extra "Object Class Name", NicInfo::get_object_class_name( @objectclass )
70
+ @config.logger.terse "Host Name", NicInfo::get_ldhName( @objectclass )
71
+ @config.logger.terse "IDN Host Name", NicInfo::get_unicodeName( @objectclass )
72
+ ipAddrs = @objectclass[ "ipAddresses" ]
73
+ if ipAddrs
74
+ v6Addrs = ipAddrs[ "v6" ]
75
+ v6Addrs.each do |v6|
76
+ @config.logger.terse "IPv6 Address", v6
77
+ end if v6Addrs
78
+ v4Addrs = ipAddrs[ "v4" ]
79
+ v4Addrs.each do |v4|
80
+ @config.logger.terse "IPv4 Address", v4
81
+ end if v4Addrs
82
+ end
83
+ @common.display_status @objectclass
84
+ @common.display_events @objectclass
85
+ @common.display_as_events_actors @asEventActors
86
+ @common.display_port43 @objectclass
87
+ @common.display_remarks @objectclass
88
+ @common.display_links( get_cn, @objectclass )
89
+ @config.logger.end_data_item
90
+ end
91
+
92
+ def get_cn
93
+ handle = NicInfo::get_handle @objectclass
94
+ handle = NicInfo::get_ldhName @objectclass if !handle
95
+ handle = "(unidentifiable nameserver #{object_id})" if !handle
96
+ if (name = NicInfo::get_ldhName( @objectclass ) ) != nil
97
+ return "#{name} ( #{handle} )"
98
+ end
99
+ return handle
100
+ end
101
+
102
+ def to_node
103
+ DataNode.new( get_cn, nil, NicInfo::get_self_link( NicInfo::get_links( @objectclass, @config ) ) )
104
+ end
105
+
106
+ end
107
+
108
+ end
data/lib/utils.rb ADDED
@@ -0,0 +1,189 @@
1
+ # Copyright (C) 2011,2012,2013,2014 American Registry for Internet Numbers
2
+ #
3
+ # Permission to use, copy, modify, and/or distribute this software for any
4
+ # purpose with or without fee is hereby granted, provided that the above
5
+ # copyright notice and this permission notice appear in all copies.
6
+ #
7
+ # THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
8
+ # WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
9
+ # MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
10
+ # ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
11
+ # WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
12
+ # ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR
13
+ # IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
14
+
15
+
16
+ require 'stringio'
17
+ require 'uri'
18
+ require 'config'
19
+
20
+ module NicInfo
21
+
22
+ def NicInfo.make_safe( url )
23
+ safe = URI.escape( url )
24
+ safe = URI.escape( safe, "!*'();:@&=+$,/?#[]" )
25
+ return safe
26
+ end
27
+
28
+ def NicInfo.get_secure_dns json_data
29
+ return json_data[ "secureDNS" ]
30
+ end
31
+
32
+ def NicInfo.get_ds_data_objs json_data
33
+ secure_dns = NicInfo::get_secure_dns json_data
34
+ if secure_dns.instance_of? Array
35
+ secure_dns = secure_dns[ 0 ]
36
+ end
37
+ return secure_dns[ "dsData" ] if secure_dns
38
+ return nil
39
+ end
40
+
41
+ def NicInfo.get_key_data_objs json_data
42
+ secure_dns = NicInfo::get_secure_dns json_data
43
+ if secure_dns.instance_of? Array
44
+ secure_dns = secure_dns[ 0 ]
45
+ end
46
+ return secure_dns[ "keyData" ] if secure_dns
47
+ return nil
48
+ end
49
+
50
+ def NicInfo.get_algorithm json_data
51
+ return json_data[ "algorithm" ]
52
+ end
53
+
54
+ def NicInfo.get_handle json_data
55
+ return json_data[ "handle" ]
56
+ end
57
+
58
+ def NicInfo.get_object_class_name json_data
59
+ return json_data[ "objectClassName" ]
60
+ end
61
+
62
+ def NicInfo.get_ldhName json_data
63
+ return json_data[ "ldhName" ]
64
+ end
65
+
66
+ def NicInfo.get_unicodeName json_data
67
+ return json_data[ "unicodeName" ]
68
+ end
69
+
70
+ def NicInfo.get_descriptions json_data, config
71
+ return if !json_data
72
+ if json_data.instance_of?( Hash )
73
+ retval = json_data[ "description" ]
74
+ unless retval.instance_of?( Array )
75
+ config.conf_msgs << "'description' is not an array."
76
+ retval = nil
77
+ end
78
+ else
79
+ config.conf_msgs << "expected object for 'remarks' or 'notices'."
80
+ retval = nil
81
+ end
82
+ return retval
83
+ end
84
+
85
+ def NicInfo.get_entitites json_data
86
+ return json_data[ "entities" ]
87
+ end
88
+
89
+ def NicInfo.get_networks json_data
90
+ return json_data[ "networks" ]
91
+ end
92
+
93
+ def NicInfo.get_network json_data
94
+ return json_data[ "network" ]
95
+ end
96
+
97
+ def NicInfo.get_autnums json_data
98
+ return json_data[ "autnums" ]
99
+ end
100
+
101
+ def NicInfo.get_nameservers json_data
102
+ return json_data[ "nameServers" ]
103
+ end
104
+
105
+ def NicInfo.get_startAddress json_data
106
+ return json_data[ "startAddress" ]
107
+ end
108
+
109
+ def NicInfo.get_endAddress json_data
110
+ return json_data[ "endAddress" ]
111
+ end
112
+
113
+ def NicInfo.get_startAutnum json_data
114
+ return json_data[ "startAutnum" ]
115
+ end
116
+
117
+ def NicInfo.get_endAutnum json_data
118
+ return json_data[ "endAutnum" ]
119
+ end
120
+
121
+ def NicInfo.get_name json_data
122
+ return json_data[ "name" ]
123
+ end
124
+
125
+ def NicInfo.get_type json_data
126
+ return json_data[ "type" ]
127
+ end
128
+
129
+ def NicInfo.get_country json_data
130
+ return json_data[ "country" ]
131
+ end
132
+
133
+ def NicInfo.get_links json_data, config
134
+ retval = json_data[ "links" ]
135
+ return nil unless retval
136
+ if !retval.instance_of?( Array )
137
+ config.conf_msgs << "'links' is not an array."
138
+ retval = nil
139
+ end
140
+ return retval
141
+ end
142
+
143
+ def NicInfo.get_related_link links
144
+ get_link "related", links
145
+ end
146
+
147
+ def NicInfo.get_alternate_link links
148
+ get_link "alternate", links
149
+ end
150
+
151
+ def NicInfo.get_tos_link links
152
+ get_link "terms-of-service", links
153
+ end
154
+
155
+ def NicInfo.get_license_link links
156
+ get_link "license", links
157
+ end
158
+
159
+ def NicInfo.get_copyright_link links
160
+ get_link "copyright", links
161
+ end
162
+
163
+ def NicInfo.get_about_link links
164
+ get_link "about", links
165
+ end
166
+
167
+ def NicInfo.get_self_link links
168
+ get_link "self", links
169
+ end
170
+
171
+ def NicInfo.get_link rel, links
172
+ return nil if !links
173
+ links.each do |link|
174
+ if link[ "rel" ] == rel
175
+ return link[ "href" ]
176
+ end
177
+ end
178
+ return nil
179
+ end
180
+
181
+ def NicInfo.capitalize str
182
+ words = str.split( /\s/ )
183
+ words.each do |word|
184
+ word.capitalize!
185
+ end
186
+ return words.join( " " )
187
+ end
188
+
189
+ end
metadata ADDED
@@ -0,0 +1,90 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: nicinfo
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.2.0
5
+ platform: ruby
6
+ authors:
7
+ - Andrew Newton
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2015-06-03 00:00:00.000000000 Z
12
+ dependencies: []
13
+ description: A command-line RDAP client.
14
+ email: andy@arin.net
15
+ executables:
16
+ - nicinfo
17
+ extensions: []
18
+ extra_rdoc_files: []
19
+ files:
20
+ - bin/nicinfo
21
+ - lib/autnum.rb
22
+ - lib/bootstrap.rb
23
+ - lib/bsfiles/asn.json
24
+ - lib/bsfiles/dns.json
25
+ - lib/bsfiles/entity.json
26
+ - lib/bsfiles/ipv4.json
27
+ - lib/bsfiles/ipv6.json
28
+ - lib/cache.rb
29
+ - lib/common_json.rb
30
+ - lib/common_names.rb
31
+ - lib/config.rb
32
+ - lib/constants.rb
33
+ - lib/data_tree.rb
34
+ - lib/demo/autnum.json
35
+ - lib/demo/domain-dnr.json
36
+ - lib/demo/domain-rir.json
37
+ - lib/demo/domains.json
38
+ - lib/demo/entities.json
39
+ - lib/demo/entity-dnr.json
40
+ - lib/demo/entity-rir.json
41
+ - lib/demo/error-code.json
42
+ - lib/demo/help.json
43
+ - lib/demo/ip.json
44
+ - lib/demo/nameservers.json
45
+ - lib/demo/ns-simple.json
46
+ - lib/demo/ns-very-simple.json
47
+ - lib/demo/ns.json
48
+ - lib/demo/simple-ip.json
49
+ - lib/demo/simple.json
50
+ - lib/domain.rb
51
+ - lib/ds_data.rb
52
+ - lib/entity.rb
53
+ - lib/enum.rb
54
+ - lib/error_code.rb
55
+ - lib/female-first-names.txt
56
+ - lib/ip.rb
57
+ - lib/key_data.rb
58
+ - lib/last-names.txt
59
+ - lib/male-first-names.txt
60
+ - lib/nicinfo_logger.rb
61
+ - lib/nicinfo_main.rb
62
+ - lib/notices.rb
63
+ - lib/ns.rb
64
+ - lib/utils.rb
65
+ homepage: https://github.com/arinlabs/nicinfo
66
+ licenses:
67
+ - ISC
68
+ metadata: {}
69
+ post_install_message:
70
+ rdoc_options: []
71
+ require_paths:
72
+ - lib
73
+ required_ruby_version: !ruby/object:Gem::Requirement
74
+ requirements:
75
+ - - '>='
76
+ - !ruby/object:Gem::Version
77
+ version: '0'
78
+ required_rubygems_version: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - '>='
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ requirements: []
84
+ rubyforge_project:
85
+ rubygems_version: 2.4.5
86
+ signing_key:
87
+ specification_version: 4
88
+ summary: RDAP Client
89
+ test_files: []
90
+ has_rdoc: