pwhois 1.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (9) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +9 -0
  3. data/Gemfile +4 -0
  4. data/LICENSE +21 -0
  5. data/README.md +193 -0
  6. data/Rakefile +1 -0
  7. data/bin/pwhois +231 -0
  8. data/pwhois.gemspec +15 -0
  9. metadata +66 -0
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 6f86327a3c61add78061dea96a88b52668725b54
4
+ data.tar.gz: 4965237b1a78a0096c8982f17f5a36daab0dda7a
5
+ SHA512:
6
+ metadata.gz: 16646eb76c116d0c12afef82e76e53cb4fcc1e0ce73aab181103f9ec91a2a6489805e4f618820830175dcd5099906072e1b124471a4021fe28da3e7a4fcd6abe
7
+ data.tar.gz: c10c8f084cddaf62e22816546c559dc356cf839cc148250fdf7042a055ea7632b678ebad9f7e72f608da933f92388413bcb9c9f7f9188de0e15444d57eaf5433
data/.gitignore ADDED
@@ -0,0 +1,9 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in pwhois.gemspec
4
+ gemspec
data/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2014 Seth Wright
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,193 @@
1
+ pwhois
2
+ ======
3
+
4
+ `pwhois` is a small command-line utility that takes advantage of the
5
+ [Ruby Whois][whois] module to parse Whois results and display them in a
6
+ coherent style. From their [Parsers][parsers] page:
7
+
8
+ > I know what you are thinking and the record is yes: in order to support
9
+ > all existing WHOIS servers and registrars, the Whois library should
10
+ > provide more than 500 different parsers. And this is exactly one of the
11
+ > major development goal.
12
+
13
+ This utility will not give you the full, parsed output of a whois query
14
+ (yet). It appears that the [Ruby Whois][whois] module supports only a
15
+ subset of possible returned properties. See the gem's
16
+ [Properties][properties] page for the list of supported properties.
17
+
18
+ *(This was a simple project to help me learn a little bit about Ruby. If
19
+ you're a Ruby guru, please don't look too closely at the code. Or if you
20
+ do, let me know where I could do things better. Thanks!)*
21
+
22
+ # Usage
23
+ $ ./pwhois -h
24
+ Usage: pwhois [options]
25
+
26
+ Specific options:
27
+ -v, --[no-]verbose Run verbosely
28
+ -o, --output TYPE Output style. One of: csv, tsv, table, list
29
+ -a, --attributes x,y,z Attributes to return.
30
+ -h, --help Show this message
31
+
32
+ # Output Styles
33
+
34
+ ## CSV (Comma-Separated Values)
35
+ $ ./pwhois -o csv github.com
36
+ Domain,Created On,Updated On,Registrar Name
37
+ github.com,2013-06-14 19:07:02 -0400,2013-11-27 07:00:15 -0500,"MarkMonitor, Inc."
38
+
39
+
40
+ ## TSV (Tab-Separated Values)
41
+ $ ./pwhois -o tsv github.com
42
+ Domain Created On Updated On Registrar Name
43
+ github.com 2013-06-14 19:07:02 -0400 2013-11-27 07:00:15 -0500 MarkMonitor, Inc.
44
+
45
+
46
+ ## List (Default Style)
47
+ $ ./pwhois -o list github.com
48
+ Domain : github.com
49
+ Created On : 2013-06-14 19:07:02 -0400
50
+ Updated On : 2013-11-27 07:00:15 -0500
51
+ Registrar Name: MarkMonitor, Inc.
52
+
53
+
54
+ ## Table
55
+ $ ./pwhois -o table github.com
56
+ Domain Created On Updated On Registrar Name
57
+ ---------- ------------------------- ------------------------- -----------------
58
+ github.com 2013-06-14 19:07:02 -0400 2013-11-27 07:00:15 -0500 MarkMonitor, Inc.
59
+
60
+
61
+ # Multiple Queries
62
+
63
+ You can give `pwhois` a list of domains and it will return the results in
64
+ a format useful to the style.
65
+
66
+ ## CSV/TSV style
67
+
68
+ The header line is printed only once:
69
+
70
+ $ ./pwhois -o csv $(<domains.txt)
71
+ Domain,Created On,Updated On,Registrar Name
72
+ github.com,2013-06-14 19:07:02 -0400,2013-11-27 07:00:15 -0500,"MarkMonitor, Inc."
73
+ google.com,2002-10-02 03:00:00 -0400,2014-05-19 07:00:17 -0400,"MarkMonitor, Inc."
74
+ cnn.com,1993-09-22 00:00:00 -0400,2013-11-27 04:31:40 -0500,"CSC CORPORATE DOMAINS, INC."
75
+ twitter.com,2000-01-21 11:28:17 -0500,2013-11-28 05:57:01 -0500,"CSC CORPORATE DOMAINS, INC."
76
+ ruby-whois.org,2010-02-03 18:03:27 UTC,2014-03-14 01:20:28 UTC,"eNom, Inc. (R39-LROR)"
77
+
78
+
79
+ ## List style
80
+
81
+ Individual records are separated by a blank line:
82
+
83
+ $ ./pwhois -o list $(<domains.txt)
84
+ Domain : github.com
85
+ Created On : 2013-06-14 19:07:02 -0400
86
+ Updated On : 2013-11-27 07:00:15 -0500
87
+ Registrar Name: MarkMonitor, Inc.
88
+
89
+ Domain : google.com
90
+ Created On : 2002-10-02 03:00:00 -0400
91
+ Updated On : 2014-05-19 07:00:17 -0400
92
+ Registrar Name: MarkMonitor, Inc.
93
+
94
+ Domain : cnn.com
95
+ Created On : 1993-09-22 00:00:00 -0400
96
+ Updated On : 2013-11-27 04:31:40 -0500
97
+ Registrar Name: CSC CORPORATE DOMAINS, INC.
98
+
99
+ Domain : twitter.com
100
+ Created On : 2000-01-21 11:28:17 -0500
101
+ Updated On : 2013-11-28 05:57:01 -0500
102
+ Registrar Name: CSC CORPORATE DOMAINS, INC.
103
+
104
+ Domain : ruby-whois.org
105
+ Created On : 2010-02-03 18:03:27 UTC
106
+ Updated On : 2014-03-14 01:20:28 UTC
107
+ Registrar Name: eNom, Inc. (R39-LROR)
108
+
109
+
110
+ ## Table Style
111
+
112
+ Columns are sized appropriately for the content. (Table output with
113
+ multiple queries will not output results until the last query is finished,
114
+ in order to figure out proper column widths. If you want to know what's
115
+ going on, use the `-v|--verbose` option.)
116
+
117
+ $ ./pwhois -o table $(<domains.txt)
118
+ Domain Created On Updated On Registrar Name
119
+ -------------- ------------------------- ------------------------- ---------------------------
120
+ github.com 2013-06-14 19:07:02 -0400 2013-11-27 07:00:15 -0500 MarkMonitor, Inc.
121
+ google.com 2002-10-02 03:00:00 -0400 2014-05-19 07:00:17 -0400 MarkMonitor, Inc.
122
+ cnn.com 1993-09-22 00:00:00 -0400 2013-11-27 04:31:40 -0500 CSC CORPORATE DOMAINS, INC.
123
+ twitter.com 2000-01-21 11:28:17 -0500 2013-11-28 05:57:01 -0500 CSC CORPORATE DOMAINS, INC.
124
+ ruby-whois.org 2010-02-03 18:03:27 UTC 2014-03-14 01:20:28 UTC eNom, Inc. (R39-LROR)
125
+
126
+
127
+ # Specifying Attributes to Print
128
+
129
+ See the [Ruby Whois][whois] documentation for the various
130
+ [properties][properties] that can be printed. Currently there is no way to
131
+ specify *all* properties, sorry. (Note that `pwhois` and this document
132
+ refer to properties as *attributes*, because reasons.)
133
+
134
+ ## Examples
135
+
136
+ The default set of attributes printed by the utility are `domain`,
137
+ `created_on`, `updated_on`, and `registrar_name`. If you want to specify
138
+ another set of attributes you're interested in, you can do so with the
139
+ `-a|--attributes` option:
140
+
141
+ $ ./pwhois -a domain,created_on,status github.com
142
+ Domain : github.com
143
+ Created On: 2013-06-14 19:07:02 -0400
144
+ Status : registered
145
+
146
+ Note that attributes under Registrar can be specified by prepending
147
+ "registrar\_" to the attribute name. For instance, to print the registrar
148
+ name and ID:
149
+
150
+ $ ./pwhois -a domain,registrar_name,registrar_id crosse.org
151
+ Domain : crosse.org
152
+ Registrar Name: eNom, Inc. (R39-LROR)
153
+ Registrar Id : 48
154
+
155
+ (I would like to handle `registrant_contacts`, `admin_contacts`,
156
+ `technical_contacts`, and `nameservers` similarly, but I haven't done
157
+ so yet.)
158
+
159
+ # Verbose Mode
160
+
161
+ Useful for table-style output with multiple queries, or if you just want to
162
+ see what sort of weird verbose logging I do, you can enable verbose mode:
163
+
164
+ $ ./pwhois -v -o table $(<domains.txt)
165
+ [ collating data, please wait... ]
166
+ [ Querying whois for github.com... ]
167
+ [ Querying whois for google.com... ]
168
+ [ Querying whois for cnn.com... ]
169
+ [ Querying whois for twitter.com... ]
170
+ [ Querying whois for ruby-whois.org... ]
171
+ Domain Created On Updated On Registrar Name
172
+ -------------- ------------------------- ------------------------- ---------------------------
173
+ github.com 2013-06-14 19:07:02 -0400 2013-11-27 07:00:15 -0500 MarkMonitor, Inc.
174
+ google.com 2002-10-02 03:00:00 -0400 2014-05-19 07:00:17 -0400 MarkMonitor, Inc.
175
+ cnn.com 1993-09-22 00:00:00 -0400 2013-11-27 04:31:40 -0500 CSC CORPORATE DOMAINS, INC.
176
+ twitter.com 2000-01-21 11:28:17 -0500 2013-11-28 05:57:01 -0500 CSC CORPORATE DOMAINS, INC.
177
+ ruby-whois.org 2010-02-03 18:03:27 UTC 2014-03-14 01:20:28 UTC eNom, Inc. (R39-LROR)
178
+
179
+ Verbose output is printed to `stderr`.
180
+
181
+
182
+ # TODO
183
+
184
+ - Print datetime values in either localtime or UTC, but at least in the same
185
+ format.
186
+ - Handle `registrant_contacts`, `admin_contacts`, `technical_contacts`, and
187
+ `nameservers`. Note that these are potentially arrays of things.
188
+ - Handle timeouts and ECONNRESETs in a happier fashion than dying horribly.
189
+ - Learn Ruby.
190
+
191
+ [whois]: http://ruby-whois.org
192
+ [properties]: http://ruby-whois.org/manual/parser/properties/
193
+ [parsers]: http://ruby-whois.org/manual/parser/
data/Rakefile ADDED
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
data/bin/pwhois ADDED
@@ -0,0 +1,231 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'optparse'
4
+ require 'whois'
5
+
6
+ class Symbol
7
+ def titleize()
8
+ to_s.split('_').map { |words| words.capitalize }.join(' ')
9
+ end
10
+ end
11
+
12
+ class WhoisParser
13
+ # Constants
14
+ UNKNOWN = "UNKNOWN"
15
+
16
+ # Class variables
17
+ @@OUTPUT_STYLES = [ :csv, :tsv, :table, :list ]
18
+
19
+ # Instance variables
20
+ attr_accessor :verbose, :output_style, :attributes
21
+
22
+ def self.output_styles
23
+ @@OUTPUT_STYLES
24
+ end # output_styles
25
+
26
+
27
+ def initialize()
28
+ @whois_client = Whois::Client.new
29
+ @verbose = false
30
+ @output_style = :list
31
+ @attributes = [:domain, :created_on, :updated_on, :registrar_name]
32
+ end # initialize()
33
+
34
+
35
+ def get_attr(record, attr)
36
+ if record == nil
37
+ raise(ArgumentError, ":record must not be nil")
38
+ end
39
+
40
+ obj,a = nil
41
+
42
+ if "#{attr}".start_with?("registrar")
43
+ a = "#{attr}".split('_')[1]
44
+ get_attr(record.registrar, a)
45
+ else
46
+ if record.respond_to?(attr)
47
+ record.send(attr)
48
+ else
49
+ raise(ArgumentError, "Warning: attribute \"#{ attr }\" does not exist for this domain")
50
+ end
51
+ end
52
+ end # get_attr()
53
+
54
+
55
+ def query(q)
56
+ query_list([ q ])
57
+ end # query()
58
+
59
+
60
+ def query_list(querys)
61
+ print_header()
62
+
63
+ # only required for table listings.
64
+ results = []
65
+
66
+ querys.each do |q|
67
+ result = Hash.new
68
+ begin
69
+ print_verbose("Querying whois for #{q}...")
70
+ record = @whois_client.lookup(q)
71
+ if !record
72
+ $stderr.puts "wtf just happened"
73
+ end
74
+
75
+ attributes.each do |a|
76
+ begin
77
+ result[a] = get_attr(record, a)
78
+ rescue ArgumentError => e
79
+ $stderr.puts e.message
80
+ end
81
+ end
82
+
83
+ if output_style == :table
84
+ results.push(result)
85
+ else
86
+ print_item(result)
87
+ end
88
+ rescue Whois::ConnectionError => e
89
+ $stderr.puts e.message
90
+ rescue NoMethodError => e
91
+ $stderr.puts e.message
92
+ $stderr.puts e.backtrace
93
+ rescue SystemExit,Interrupt
94
+ print_verbose("Ctrl-C pressed, exiting")
95
+ exit
96
+ rescue StandardError => e
97
+ $stderr.puts e.message
98
+ $stderr.puts e.backtrace
99
+ exit
100
+ end
101
+ end # querys.each
102
+
103
+ if output_style == :table
104
+ print_table(results)
105
+ end
106
+ end # query_list()
107
+
108
+
109
+ private
110
+ def print_verbose(msg)
111
+ if verbose
112
+ $stderr.puts("[ #{msg} ]")
113
+ end
114
+ end # verbose()
115
+
116
+
117
+ private
118
+ def quote_if_include(str, char)
119
+ if "#{str}".include?(char)
120
+ "\"#{str}\""
121
+ else
122
+ "#{str}"
123
+ end
124
+ end
125
+
126
+
127
+ private
128
+ def print_header()
129
+ case output_style
130
+ when :csv
131
+ puts attributes.map{ |a| quote_if_include(a.titleize, ',') }.join(',')
132
+ when :tsv
133
+ puts attributes.map{ |a| quote_if_include(a.titleize, "\t") }.join("\t")
134
+ when :table
135
+ print_verbose("collating data, please wait...")
136
+ end
137
+ end # print_header()
138
+
139
+
140
+ private
141
+ def print_item(result)
142
+ case output_style
143
+ when :csv
144
+ puts attributes.map{ |a| quote_if_include(result[a], ',') }.join(',')
145
+ when :tsv
146
+ puts attributes.map{ |a| result[a] }.join("\t")
147
+ when :list
148
+ print_list_item(result)
149
+ end
150
+ end # print_item()
151
+
152
+
153
+ private
154
+ def print_list_item(result)
155
+ l = attributes.map{ |a| a.length }.sort.last
156
+ attributes.each do |a|
157
+ printf("%-#{l}s:\t%s\n", a.titleize, result[a])
158
+ end
159
+ puts
160
+ end # print_list_item()
161
+
162
+
163
+ private
164
+ def print_table(records)
165
+ attr_lengths = Hash.new
166
+ attributes.each do |a|
167
+ l = records.map{ |r| r[a].to_s.length }.sort.last
168
+ attr_lengths[a] = (a.length > l) ? a.length : l
169
+ end
170
+
171
+ # print the header row
172
+ attributes.each do |a|
173
+ printf("%-#{attr_lengths[a]}s ", a.titleize)
174
+ end
175
+ printf("\n")
176
+ attributes.each do |a|
177
+ print '-' * attr_lengths[a]
178
+ print ' '
179
+ end
180
+ printf("\n")
181
+
182
+ records.each do |r|
183
+ attributes.each do |a|
184
+ printf("%-#{attr_lengths[a]}s ", r[a])
185
+ end
186
+ printf("\n")
187
+ end
188
+ end # print_table()
189
+
190
+ end # class WhoisParser
191
+
192
+
193
+ w = WhoisParser.new
194
+
195
+ OptionParser.new do |opts|
196
+ opts.banner = "Usage: #{opts.program_name} [options]"
197
+
198
+ opts.separator ""
199
+ opts.separator "Specific options:"
200
+
201
+ opts.on("-v", "--[no-]verbose", "Run verbosely") do |v|
202
+ w.verbose = v
203
+ end
204
+
205
+ output_list = WhoisParser.output_styles.join(', ')
206
+ opts.on("-o", "--output TYPE", WhoisParser.output_styles,
207
+ "Output style. One of: #{output_list}") do |style|
208
+ w.output_style = style
209
+ end
210
+
211
+ opts.on("-a", "--attributes x,y,z", Array,
212
+ "Attributes to return.") do |list|
213
+ w.attributes = Array.new(list.map{ |i| i.to_sym })
214
+ if !w.attributes.include?(:domain)
215
+ w.attributes.push(:domain)
216
+ end
217
+ w.attributes.freeze
218
+ end
219
+
220
+ opts.on_tail("-h", "--help", "Show this message") do
221
+ puts opts
222
+ exit
223
+ end
224
+
225
+ #opts.on_tail("--version", "Show version") do
226
+ #puts ::Version.join('.')
227
+ #exit
228
+ #end
229
+ end.parse!
230
+
231
+ w.query_list(ARGV)
data/pwhois.gemspec ADDED
@@ -0,0 +1,15 @@
1
+ # coding: utf-8
2
+ Gem::Specification.new do |spec|
3
+ spec.name = "pwhois"
4
+ spec.version = "1.0.1"
5
+ spec.authors = ["Seth Wright"]
6
+ spec.email = ["seth@crosse.org"]
7
+
8
+ spec.summary = %q{Parse whois results and display them in a coherent style.}
9
+ spec.homepage = "https://github.com/Crosse/pwhois"
10
+ spec.license = "ISC"
11
+
12
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
13
+ spec.executables = ["pwhois"]
14
+ spec.add_runtime_dependency "whois"
15
+ end
metadata ADDED
@@ -0,0 +1,66 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: pwhois
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Seth Wright
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2015-11-17 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: whois
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - '>='
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - '>='
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ description:
28
+ email:
29
+ - seth@crosse.org
30
+ executables:
31
+ - pwhois
32
+ extensions: []
33
+ extra_rdoc_files: []
34
+ files:
35
+ - .gitignore
36
+ - Gemfile
37
+ - LICENSE
38
+ - README.md
39
+ - Rakefile
40
+ - bin/pwhois
41
+ - pwhois.gemspec
42
+ homepage: https://github.com/Crosse/pwhois
43
+ licenses:
44
+ - ISC
45
+ metadata: {}
46
+ post_install_message:
47
+ rdoc_options: []
48
+ require_paths:
49
+ - lib
50
+ required_ruby_version: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - '>='
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ required_rubygems_version: !ruby/object:Gem::Requirement
56
+ requirements:
57
+ - - '>='
58
+ - !ruby/object:Gem::Version
59
+ version: '0'
60
+ requirements: []
61
+ rubyforge_project:
62
+ rubygems_version: 2.0.14
63
+ signing_key:
64
+ specification_version: 4
65
+ summary: Parse whois results and display them in a coherent style.
66
+ test_files: []