hansef-checkdomain 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- data/History.txt +4 -0
- data/Manifest.txt +16 -0
- data/PostInstall.txt +7 -0
- data/README.rdoc +46 -0
- data/Rakefile +28 -0
- data/bin/checkdomain +10 -0
- data/lib/checkdomain.rb +59 -0
- data/lib/checkdomain/cli.rb +35 -0
- data/lib/checkdomain/domain.rb +63 -0
- data/lib/checkdomain/search.rb +54 -0
- data/script/console +10 -0
- data/script/destroy +14 -0
- data/script/generate +14 -0
- data/test/test_checkdomain.rb +11 -0
- data/test/test_checkdomain_cli.rb +14 -0
- data/test/test_helper.rb +3 -0
- metadata +75 -0
data/History.txt
ADDED
data/Manifest.txt
ADDED
@@ -0,0 +1,16 @@
|
|
1
|
+
History.txt
|
2
|
+
Manifest.txt
|
3
|
+
PostInstall.txt
|
4
|
+
README.rdoc
|
5
|
+
Rakefile
|
6
|
+
bin/checkdomain
|
7
|
+
lib/checkdomain.rb
|
8
|
+
lib/checkdomain/cli.rb
|
9
|
+
lib/checkdomain/domain.rb
|
10
|
+
lib/checkdomain/search.rb
|
11
|
+
script/console
|
12
|
+
script/destroy
|
13
|
+
script/generate
|
14
|
+
test/test_checkdomain.rb
|
15
|
+
test/test_checkdomain_cli.rb
|
16
|
+
test/test_helper.rb
|
data/PostInstall.txt
ADDED
data/README.rdoc
ADDED
@@ -0,0 +1,46 @@
|
|
1
|
+
= checkdomain
|
2
|
+
|
3
|
+
* http://github.com/hansef/checkdomain/
|
4
|
+
|
5
|
+
== DESCRIPTION:
|
6
|
+
|
7
|
+
Easily check a domain's availability from the commandline.
|
8
|
+
|
9
|
+
Usage: checkdomain domain [domain2 domain3 etc.]
|
10
|
+
|
11
|
+
You can also put comma-separated terms in square brackets and they will be expanded: checkdomain example.[com,org,net]
|
12
|
+
|
13
|
+
This will result in checks for each of the following:
|
14
|
+
|
15
|
+
* example.com
|
16
|
+
* example.org
|
17
|
+
* example.net
|
18
|
+
|
19
|
+
== INSTALL:
|
20
|
+
|
21
|
+
* FIX (sudo gem install, anything else)
|
22
|
+
|
23
|
+
== LICENSE:
|
24
|
+
|
25
|
+
(The MIT License)
|
26
|
+
|
27
|
+
Copyright (c) 2009 Hans Friedrich
|
28
|
+
|
29
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
30
|
+
a copy of this software and associated documentation files (the
|
31
|
+
'Software'), to deal in the Software without restriction, including
|
32
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
33
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
34
|
+
permit persons to whom the Software is furnished to do so, subject to
|
35
|
+
the following conditions:
|
36
|
+
|
37
|
+
The above copyright notice and this permission notice shall be
|
38
|
+
included in all copies or substantial portions of the Software.
|
39
|
+
|
40
|
+
THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
|
41
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
42
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
43
|
+
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
|
44
|
+
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
|
45
|
+
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
|
46
|
+
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/Rakefile
ADDED
@@ -0,0 +1,28 @@
|
|
1
|
+
%w[rubygems rake rake/clean fileutils newgem rubigen].each { |f| require f }
|
2
|
+
require File.dirname(__FILE__) + '/lib/checkdomain'
|
3
|
+
|
4
|
+
# Generate all the Rake tasks
|
5
|
+
# Run 'rake -T' to see list of generated tasks (from gem root directory)
|
6
|
+
$hoe = Hoe.new('checkdomain', CheckDomain::VERSION) do |p|
|
7
|
+
p.developer('FIXME full name', 'FIXME email')
|
8
|
+
p.changes = p.paragraphs_of("History.txt", 0..1).join("\n\n")
|
9
|
+
p.post_install_message = 'PostInstall.txt' # TODO remove if post-install message not required
|
10
|
+
p.rubyforge_name = p.name # TODO this is default value
|
11
|
+
# p.extra_deps = [
|
12
|
+
# ['activesupport','>= 2.0.2'],
|
13
|
+
# ]
|
14
|
+
p.extra_dev_deps = [
|
15
|
+
['newgem', ">= #{::Newgem::VERSION}"]
|
16
|
+
]
|
17
|
+
|
18
|
+
p.clean_globs |= %w[**/.DS_Store tmp *.log]
|
19
|
+
path = (p.rubyforge_name == p.name) ? p.rubyforge_name : "\#{p.rubyforge_name}/\#{p.name}"
|
20
|
+
p.remote_rdoc_dir = File.join(path.gsub(/^#{p.rubyforge_name}\/?/,''), 'rdoc')
|
21
|
+
p.rsync_args = '-av --delete --ignore-errors'
|
22
|
+
end
|
23
|
+
|
24
|
+
require 'newgem/tasks' # load /tasks/*.rake
|
25
|
+
Dir['tasks/**/*.rake'].each { |t| load t }
|
26
|
+
|
27
|
+
# TODO - want other tests/tasks run by default? Add them to the list
|
28
|
+
# task :default => [:spec, :features]
|
data/bin/checkdomain
ADDED
data/lib/checkdomain.rb
ADDED
@@ -0,0 +1,59 @@
|
|
1
|
+
$:.unshift(File.dirname(__FILE__)) unless
|
2
|
+
$:.include?(File.dirname(__FILE__)) || $:.include?(File.expand_path(File.dirname(__FILE__)))
|
3
|
+
|
4
|
+
require 'rubygems'
|
5
|
+
require 'net/dns/resolver'
|
6
|
+
|
7
|
+
require 'checkdomain/search'
|
8
|
+
require 'checkdomain/domain'
|
9
|
+
|
10
|
+
module CheckDomain
|
11
|
+
VERSION = '1.0.0'
|
12
|
+
|
13
|
+
TLDS = %W(
|
14
|
+
aero asia biz cat com coop edu gov info int jobs mil mobi museum name net org
|
15
|
+
pro tel travel ac ad ae af ag ai al am an ao aq ar as at au aw ax az ba bb bd
|
16
|
+
be bf bg bh bi bj bm bn bo br bs bt bv bw by bz ca cc cd cf cg ch ci ck cl cm
|
17
|
+
cn co cr cu cv cx cy cz de dj dk dm do dz ec ee eg er es et eu fi fj fk fm fo
|
18
|
+
fr ga gb gd ge gf gg gh gi gl gm gn gp gq gr gs gt gu gw gy hk hm hn hr ht hu
|
19
|
+
id ie il im in io iq ir is it je jm jo jp ke kg kh ki km kn kp kr kw ky kz la
|
20
|
+
lb lc li lk lr ls lt lu lv ly ma mc md me mg mh mk ml mm mn mo mp mq mr ms mt
|
21
|
+
mu mv mw mx my mz na nc ne nf ng ni nl no np nr nu nz om pa pe pf pg ph pk pl
|
22
|
+
pm pn pr ps pt pw py qa re ro rs ru rw sa sb sc sd se sg sh si sj sk sl sm sn
|
23
|
+
so sr st su sv sy sz tc td tf tg th tj tk tl tm tn to tp tr tt tv tw tz ua ug
|
24
|
+
uk us uy uz va vc ve vg vi vn vu wf ws ye yt yu za zm zw
|
25
|
+
)
|
26
|
+
|
27
|
+
REGEX_DOMAIN = /^(([a-z0-9\-]+\.)+)(#{TLDS.join('|')})$/
|
28
|
+
end
|
29
|
+
|
30
|
+
module Net
|
31
|
+
module DNS
|
32
|
+
class Resolver
|
33
|
+
# fixes platform for darwin
|
34
|
+
def parse_config_file
|
35
|
+
if RUBY_PLATFORM =~ /mswin/
|
36
|
+
require 'win32/resolv'
|
37
|
+
arr = Win32::Resolv.get_resolv_info
|
38
|
+
self.domain = arr[0]
|
39
|
+
self.nameservers = arr[1]
|
40
|
+
else
|
41
|
+
IO.foreach(@config[:config_file]) do |line|
|
42
|
+
line.gsub!(/\s*[;#].*/,"")
|
43
|
+
next unless line =~ /\S/
|
44
|
+
case line
|
45
|
+
when /^\s*domain\s+(\S+)/
|
46
|
+
self.domain = $1
|
47
|
+
when /^\s*search\s+(.*)/
|
48
|
+
self.searchlist = $1.split(" ")
|
49
|
+
when /^\s*nameserver\s+(.*)/
|
50
|
+
self.nameservers = $1.split(" ")
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
class ResolverError < StandardError; end
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|
@@ -0,0 +1,35 @@
|
|
1
|
+
require 'optparse'
|
2
|
+
|
3
|
+
module CheckDomain
|
4
|
+
class CLI
|
5
|
+
def self.execute(stdout, arguments=[])
|
6
|
+
options = {
|
7
|
+
:domains => ARGV[0].to_s.strip.empty? ? nil : ARGV
|
8
|
+
}
|
9
|
+
mandatory_options = %w( domains )
|
10
|
+
|
11
|
+
parser = OptionParser.new do |opts|
|
12
|
+
opts.banner = <<-BANNER.gsub(/^ /,'')
|
13
|
+
Easily check a domain's availability from the commandline.
|
14
|
+
|
15
|
+
Usage: #{File.basename($0)} domain [domain2 domain3 etc.] [options]
|
16
|
+
|
17
|
+
Options are:
|
18
|
+
BANNER
|
19
|
+
opts.separator ""
|
20
|
+
opts.on("-h", "--help",
|
21
|
+
"Show this help message.") { stdout.puts opts; exit }
|
22
|
+
opts.parse!(arguments)
|
23
|
+
|
24
|
+
if mandatory_options && mandatory_options.find { |option| options[option.to_sym].nil? }
|
25
|
+
stdout.puts opts; exit
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
path = options[:path]
|
30
|
+
|
31
|
+
search = CheckDomain::Search.new
|
32
|
+
search.run(options[:domains])
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
@@ -0,0 +1,63 @@
|
|
1
|
+
module CheckDomain
|
2
|
+
class Domain
|
3
|
+
attr_accessor :name
|
4
|
+
attr_accessor :available
|
5
|
+
attr_accessor :message
|
6
|
+
|
7
|
+
def initialize(options = {:name => nil})
|
8
|
+
self.name = options[:name]
|
9
|
+
end
|
10
|
+
|
11
|
+
def availability!
|
12
|
+
if !(self.name =~ REGEX_DOMAIN) then
|
13
|
+
is_invalid
|
14
|
+
else
|
15
|
+
if (nx_domain? || opendns_nxdomain?)
|
16
|
+
if whois_match? then
|
17
|
+
is_taken
|
18
|
+
else
|
19
|
+
is_available
|
20
|
+
end
|
21
|
+
else
|
22
|
+
is_taken
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
def nx_domain?
|
28
|
+
answer = resolver.search(self.name)
|
29
|
+
answer.header.rCode.type == "NXDomain"
|
30
|
+
end
|
31
|
+
|
32
|
+
def opendns_nxdomain?
|
33
|
+
ips = []
|
34
|
+
resolver.search(self.name, Net::DNS::A).each_address do |ip|
|
35
|
+
ips << ip.to_s
|
36
|
+
end
|
37
|
+
ips.include?("208.67.216.132")
|
38
|
+
end
|
39
|
+
|
40
|
+
def whois_match?
|
41
|
+
!`whois tenderapp.net`.match("(No match for|NOT FOUND)")
|
42
|
+
end
|
43
|
+
|
44
|
+
def is_taken
|
45
|
+
self.available = false
|
46
|
+
self.message = "TAKEN"
|
47
|
+
end
|
48
|
+
|
49
|
+
def is_available
|
50
|
+
self.available = true
|
51
|
+
self.message = "AVAILABLE"
|
52
|
+
end
|
53
|
+
|
54
|
+
def is_invalid
|
55
|
+
self.available = false
|
56
|
+
self.message = "INVALID"
|
57
|
+
end
|
58
|
+
|
59
|
+
def resolver
|
60
|
+
@resolver ||= Net::DNS::Resolver.new
|
61
|
+
end
|
62
|
+
end
|
63
|
+
end
|
@@ -0,0 +1,54 @@
|
|
1
|
+
module CheckDomain
|
2
|
+
class Search
|
3
|
+
def run(terms)
|
4
|
+
parse_domains(terms)
|
5
|
+
end
|
6
|
+
|
7
|
+
private
|
8
|
+
|
9
|
+
def parse_domains(terms)
|
10
|
+
expand(terms) do |name|
|
11
|
+
domain = Domain.new(:name => name)
|
12
|
+
domain.availability!
|
13
|
+
puts_availability(domain)
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
def expand(terms)
|
18
|
+
terms.each do |term|
|
19
|
+
unless term.is_a?(Array)
|
20
|
+
set = term.match(/\[.+?\]/)
|
21
|
+
if set
|
22
|
+
expansion = []
|
23
|
+
set.to_s[1..-2].split(",").each do |item|
|
24
|
+
expansion.push(term.gsub(set.to_s, item.strip))
|
25
|
+
end
|
26
|
+
expand(expansion) {|x| yield x}
|
27
|
+
else
|
28
|
+
yield(term)
|
29
|
+
end
|
30
|
+
else
|
31
|
+
expand(term) {|x| yield x}
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
def puts_availability(domain)
|
37
|
+
name = domain.name.ljust(50)
|
38
|
+
status = domain.available ? "[#{green(domain.message)}]" : "[#{red(domain.message)}]"
|
39
|
+
puts "#{name} #{status}"
|
40
|
+
end
|
41
|
+
|
42
|
+
def colorize(text, color_code)
|
43
|
+
"\e[#{color_code}m#{text}\e[0m"
|
44
|
+
end
|
45
|
+
|
46
|
+
def green(text)
|
47
|
+
colorize(text, 32)
|
48
|
+
end
|
49
|
+
|
50
|
+
def red(text)
|
51
|
+
colorize(text, 31)
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
data/script/console
ADDED
@@ -0,0 +1,10 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# File: script/console
|
3
|
+
irb = RUBY_PLATFORM =~ /(:?mswin|mingw)/ ? 'irb.bat' : 'irb'
|
4
|
+
|
5
|
+
libs = " -r irb/completion"
|
6
|
+
# Perhaps use a console_lib to store any extra methods I may want available in the cosole
|
7
|
+
# libs << " -r #{File.dirname(__FILE__) + '/../lib/console_lib/console_logger.rb'}"
|
8
|
+
libs << " -r #{File.dirname(__FILE__) + '/../lib/checkdomain.rb'}"
|
9
|
+
puts "Loading checkdomain gem"
|
10
|
+
exec "#{irb} #{libs} --simple-prompt"
|
data/script/destroy
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
APP_ROOT = File.expand_path(File.join(File.dirname(__FILE__), '..'))
|
3
|
+
|
4
|
+
begin
|
5
|
+
require 'rubigen'
|
6
|
+
rescue LoadError
|
7
|
+
require 'rubygems'
|
8
|
+
require 'rubigen'
|
9
|
+
end
|
10
|
+
require 'rubigen/scripts/destroy'
|
11
|
+
|
12
|
+
ARGV.shift if ['--help', '-h'].include?(ARGV[0])
|
13
|
+
RubiGen::Base.use_component_sources! [:rubygems, :newgem, :newgem_theme, :test_unit]
|
14
|
+
RubiGen::Scripts::Destroy.new.run(ARGV)
|
data/script/generate
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
APP_ROOT = File.expand_path(File.join(File.dirname(__FILE__), '..'))
|
3
|
+
|
4
|
+
begin
|
5
|
+
require 'rubigen'
|
6
|
+
rescue LoadError
|
7
|
+
require 'rubygems'
|
8
|
+
require 'rubigen'
|
9
|
+
end
|
10
|
+
require 'rubigen/scripts/generate'
|
11
|
+
|
12
|
+
ARGV.shift if ['--help', '-h'].include?(ARGV[0])
|
13
|
+
RubiGen::Base.use_component_sources! [:rubygems, :newgem, :newgem_theme, :test_unit]
|
14
|
+
RubiGen::Scripts::Generate.new.run(ARGV)
|
@@ -0,0 +1,14 @@
|
|
1
|
+
require File.join(File.dirname(__FILE__), "test_helper.rb")
|
2
|
+
require 'checkdomain/cli'
|
3
|
+
|
4
|
+
class TestCheckDomainCli < Test::Unit::TestCase
|
5
|
+
def setup
|
6
|
+
CheckDomain::CLI.execute(@stdout_io = StringIO.new, [])
|
7
|
+
@stdout_io.rewind
|
8
|
+
@stdout = @stdout_io.read
|
9
|
+
end
|
10
|
+
|
11
|
+
def test_not_print_default_output
|
12
|
+
assert_no_match(/To update this executable/, @stdout)
|
13
|
+
end
|
14
|
+
end
|
data/test/test_helper.rb
ADDED
metadata
ADDED
@@ -0,0 +1,75 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: hansef-checkdomain
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.0.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Hans Friedrich
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
|
12
|
+
date: 2009-02-15 00:00:00 -08:00
|
13
|
+
default_executable: checkdomain
|
14
|
+
dependencies: []
|
15
|
+
|
16
|
+
description: "Easily check a domain's availability from the commandline. Usage: checkdomain domain [domain2 domain3 etc.] You can also put comma-separated terms in square brackets and they will be expanded: checkdomain example.[com,org,net] This will result in checks for each of the following: * example.com * example.org * example.net"
|
17
|
+
email:
|
18
|
+
- FIXME email
|
19
|
+
executables:
|
20
|
+
- checkdomain
|
21
|
+
extensions: []
|
22
|
+
|
23
|
+
extra_rdoc_files:
|
24
|
+
- History.txt
|
25
|
+
- Manifest.txt
|
26
|
+
- PostInstall.txt
|
27
|
+
- README.rdoc
|
28
|
+
files:
|
29
|
+
- History.txt
|
30
|
+
- Manifest.txt
|
31
|
+
- PostInstall.txt
|
32
|
+
- README.rdoc
|
33
|
+
- Rakefile
|
34
|
+
- bin/checkdomain
|
35
|
+
- lib/checkdomain.rb
|
36
|
+
- lib/checkdomain/cli.rb
|
37
|
+
- lib/checkdomain/domain.rb
|
38
|
+
- lib/checkdomain/search.rb
|
39
|
+
- script/console
|
40
|
+
- script/destroy
|
41
|
+
- script/generate
|
42
|
+
- test/test_checkdomain.rb
|
43
|
+
- test/test_checkdomain_cli.rb
|
44
|
+
- test/test_helper.rb
|
45
|
+
has_rdoc: true
|
46
|
+
homepage: http://github.com/hansef/checkdomain/
|
47
|
+
post_install_message: PostInstall.txt
|
48
|
+
rdoc_options:
|
49
|
+
- --main
|
50
|
+
- README.rdoc
|
51
|
+
require_paths:
|
52
|
+
- lib
|
53
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
54
|
+
requirements:
|
55
|
+
- - ">="
|
56
|
+
- !ruby/object:Gem::Version
|
57
|
+
version: "0"
|
58
|
+
version:
|
59
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
60
|
+
requirements:
|
61
|
+
- - ">="
|
62
|
+
- !ruby/object:Gem::Version
|
63
|
+
version: "0"
|
64
|
+
version:
|
65
|
+
requirements: []
|
66
|
+
|
67
|
+
rubyforge_project: checkdomain
|
68
|
+
rubygems_version: 1.2.0
|
69
|
+
signing_key:
|
70
|
+
specification_version: 2
|
71
|
+
summary: Easily check a domain's availability from the commandline
|
72
|
+
test_files:
|
73
|
+
- test/test_checkdomain.rb
|
74
|
+
- test/test_checkdomain_cli.rb
|
75
|
+
- test/test_helper.rb
|