globetrotter 0.0.4
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 +7 -0
- data/.gitignore +23 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +29 -0
- data/Rakefile +2 -0
- data/bin/globetrotter +52 -0
- data/globetrotter.gemspec +27 -0
- data/lib/globetrotter.rb +86 -0
- data/lib/globetrotter/nameserver.rb +37 -0
- data/lib/globetrotter/version.rb +3 -0
- metadata +125 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: ba937570c70da00cf21b0eb41bb082ad1b7c8313
|
4
|
+
data.tar.gz: f0758c5c8527d68ce413aa3cbc70176bc30173fe
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 92c59ce13cfea48a0ae02cf4b664463f02fa2096a8e5f05030dca0b7259aa56d801c687436de7eda5935d0f317943bc027b3b4740e0d354ccb7722d27a1855fa
|
7
|
+
data.tar.gz: e2298d109842fe233ae300ccdbd5b32105375cc765d52a36fdcd8a9b6636491e27b6a84206a886f05f45d3ee740e38b41503f9a8d8fc7c5c9d0881bd09a0729b
|
data/.gitignore
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
*.gem
|
2
|
+
*.rbc
|
3
|
+
.bundle
|
4
|
+
.config
|
5
|
+
.yardoc
|
6
|
+
Gemfile.lock
|
7
|
+
InstalledFiles
|
8
|
+
_yardoc
|
9
|
+
coverage
|
10
|
+
doc/
|
11
|
+
lib/bundler/man
|
12
|
+
pkg
|
13
|
+
rdoc
|
14
|
+
spec/reports
|
15
|
+
test/tmp
|
16
|
+
test/version_tmp
|
17
|
+
tmp
|
18
|
+
*.bundle
|
19
|
+
*.so
|
20
|
+
*.o
|
21
|
+
*.a
|
22
|
+
mkmf.log
|
23
|
+
vendor/
|
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2014 Amplify Education, Inc.
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
# Globetrotter
|
2
|
+
|
3
|
+
TODO: Write a gem description
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
gem 'globetrotter'
|
10
|
+
|
11
|
+
And then execute:
|
12
|
+
|
13
|
+
$ bundle
|
14
|
+
|
15
|
+
Or install it yourself as:
|
16
|
+
|
17
|
+
$ gem install globetrotter
|
18
|
+
|
19
|
+
## Usage
|
20
|
+
|
21
|
+
TODO: Write usage instructions here
|
22
|
+
|
23
|
+
## Contributing
|
24
|
+
|
25
|
+
1. Fork it ( https://github.com/[my-github-username]/globetrotter/fork )
|
26
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
27
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
28
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
29
|
+
5. Create a new Pull Request
|
data/Rakefile
ADDED
data/bin/globetrotter
ADDED
@@ -0,0 +1,52 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
$:.unshift File.join(File.dirname(__FILE__), %w{.. lib})
|
4
|
+
require 'globetrotter'
|
5
|
+
require 'trollop'
|
6
|
+
|
7
|
+
opts = Trollop.options do
|
8
|
+
opt :ns_count_to_check,
|
9
|
+
'How many nameservers to query',
|
10
|
+
type: Integer,
|
11
|
+
default: 100,
|
12
|
+
short: '-c'
|
13
|
+
opt :ns_max_age_minutes,
|
14
|
+
'Query nameservers validated <= this many minutes ago',
|
15
|
+
type: Integer,
|
16
|
+
default: 60,
|
17
|
+
short: '-a'
|
18
|
+
opt :query,
|
19
|
+
'Hostname to lookup',
|
20
|
+
type: String,
|
21
|
+
default: 'googleapis.com'
|
22
|
+
opt :timeout_seconds,
|
23
|
+
'Seconds to wait before queries timeout',
|
24
|
+
type: Integer,
|
25
|
+
default: 2,
|
26
|
+
short: '-t'
|
27
|
+
opt :concurrency,
|
28
|
+
'Number of concurrent DNS requests to make',
|
29
|
+
type: Integer,
|
30
|
+
default: 100,
|
31
|
+
short: '-p'
|
32
|
+
end
|
33
|
+
|
34
|
+
ns_count_to_check = opts.ns_count_to_check
|
35
|
+
ns_max_age_minutes = opts.ns_max_age_minutes
|
36
|
+
timeout_seconds = opts.timeout_seconds
|
37
|
+
concurrency = opts.concurrency
|
38
|
+
query = opts.query
|
39
|
+
|
40
|
+
Trollop.die :ns_count_to_check, 'must be positive' if ns_count_to_check < 0
|
41
|
+
Trollop.die :ns_max_age_minutes, 'must be positive' if ns_max_age_minutes < 0
|
42
|
+
Trollop.die :timeout_seconds, 'must be positive' if ns_max_age_minutes < 0
|
43
|
+
Trollop.die :concurrency, 'must be positive' if ns_max_age_minutes < 0
|
44
|
+
|
45
|
+
gt = Globetrotter.new(
|
46
|
+
query: query,
|
47
|
+
ns_count_to_check: ns_count_to_check,
|
48
|
+
ns_max_age_minutes: ns_max_age_minutes,
|
49
|
+
timeout_seconds: timeout_seconds,
|
50
|
+
concurrency: concurrency
|
51
|
+
)
|
52
|
+
gt.run
|
@@ -0,0 +1,27 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'globetrotter/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = 'globetrotter'
|
8
|
+
spec.version = Globetrotter::VERSION
|
9
|
+
spec.authors = ['Nick Lopez']
|
10
|
+
spec.email = ['nlopez@amplify.com']
|
11
|
+
spec.summary = %q{Resolve DNS records at many different nameservers all over the world.}
|
12
|
+
# spec.description = %q{TODO: Write a longer description. Optional.}
|
13
|
+
spec.homepage = 'https://github.com/amplify-education/globetrotter'
|
14
|
+
spec.license = 'MIT'
|
15
|
+
|
16
|
+
spec.files = `git ls-files -z`.split("\x0")
|
17
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
18
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
|
+
spec.require_paths = ["lib"]
|
20
|
+
|
21
|
+
spec.add_development_dependency 'bundler', '~> 1.6'
|
22
|
+
spec.add_development_dependency 'rake'
|
23
|
+
|
24
|
+
spec.add_runtime_dependency 'rubydns', '~> 0.8'
|
25
|
+
spec.add_runtime_dependency 'trollop', '~> 2.0'
|
26
|
+
spec.add_runtime_dependency 'wrest', '~> 1.5'
|
27
|
+
end
|
data/lib/globetrotter.rb
ADDED
@@ -0,0 +1,86 @@
|
|
1
|
+
require_relative './globetrotter/version'
|
2
|
+
require_relative './globetrotter/nameserver'
|
3
|
+
require 'wrest'
|
4
|
+
require 'rubydns'
|
5
|
+
require 'time'
|
6
|
+
require 'date'
|
7
|
+
require 'set'
|
8
|
+
require 'ipaddr'
|
9
|
+
|
10
|
+
class Globetrotter
|
11
|
+
def initialize(options = {})
|
12
|
+
@ns_max_age_minutes = options.fetch(:ns_max_age_minutes, 60)
|
13
|
+
@ns_count_to_check = options.fetch(:ns_count_to_check, 100)
|
14
|
+
@timeout_seconds = options.fetch(:timeout_seconds, 2)
|
15
|
+
@query = options.fetch(:query, 'googleapis.com')
|
16
|
+
@concurrency = options.fetch(:concurrency, 100)
|
17
|
+
@ns_ips = fetch_ns_ips
|
18
|
+
end
|
19
|
+
|
20
|
+
def run
|
21
|
+
ns_count = @ns_ips.count
|
22
|
+
@ns_count_to_check = ns_count if @ns_count_to_check > ns_count
|
23
|
+
@ns_ips = @ns_ips.sample(@ns_count_to_check)
|
24
|
+
|
25
|
+
message = "Found #{ns_count} nameserver(s). "\
|
26
|
+
"Querying #{@ns_count_to_check} of those "\
|
27
|
+
"for #{query}, #{@concurrency} at a time, "\
|
28
|
+
"with a timeout of #{@timeout_seconds} second(s)."
|
29
|
+
$stderr.puts message
|
30
|
+
|
31
|
+
EM.run do
|
32
|
+
result_ips = Set.new
|
33
|
+
ok = 0
|
34
|
+
nok = 0
|
35
|
+
EM::Iterator.new(@ns_ips, @concurrency).each(
|
36
|
+
proc do |ns_ip, iter|
|
37
|
+
resolver = RubyDNS::Resolver.new(
|
38
|
+
[[:udp, ns_ip.to_s, 53]],
|
39
|
+
timeout: @timeout_seconds
|
40
|
+
)
|
41
|
+
resolver.query(query) do |response|
|
42
|
+
case response
|
43
|
+
when RubyDNS::Message
|
44
|
+
response.answer.each do |answer|
|
45
|
+
address = answer[2].address.to_s
|
46
|
+
result_ips.add(address)
|
47
|
+
end
|
48
|
+
ok += 1
|
49
|
+
iter.next
|
50
|
+
when RubyDNS::ResolutionFailure
|
51
|
+
nok += 1
|
52
|
+
iter.next
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end,
|
56
|
+
proc do
|
57
|
+
EM.stop
|
58
|
+
result_ips.each { |ip| puts ip }
|
59
|
+
$stderr.puts "#{ok} succeeded, #{nok} failed (#{ok + nok} total)"
|
60
|
+
end
|
61
|
+
)
|
62
|
+
end
|
63
|
+
end
|
64
|
+
|
65
|
+
def self.run(options = {})
|
66
|
+
new(options).run
|
67
|
+
end
|
68
|
+
|
69
|
+
private
|
70
|
+
|
71
|
+
attr_reader :ns_max_age_minutes, :ns_count_to_check, :ns_ips, :query
|
72
|
+
|
73
|
+
def fetch_ns_ips
|
74
|
+
Wrest.logger = Logger.new(STDERR)
|
75
|
+
uri = 'http://public-dns.tk/nameservers.json'.to_uri
|
76
|
+
nameservers = uri.get.deserialise.map { |data| Nameserver.new(data) }
|
77
|
+
nameservers.select do |ns|
|
78
|
+
ns.valid? && ns.ipv4? && ns.age_minutes <= ns_max_age_minutes
|
79
|
+
end.map(&:ip)
|
80
|
+
end
|
81
|
+
|
82
|
+
def resolve_with_nameserver(query, nameserver)
|
83
|
+
resolver = RubyDNS::Resolver.new([[:udp, nameserver, 53]])
|
84
|
+
resolver.query(query)
|
85
|
+
end
|
86
|
+
end
|
@@ -0,0 +1,37 @@
|
|
1
|
+
require 'wrest'
|
2
|
+
|
3
|
+
# Defines a DNS name server returned by http://public-dns.tk/
|
4
|
+
class Nameserver
|
5
|
+
include Wrest::Components::Container
|
6
|
+
|
7
|
+
always_has :id
|
8
|
+
typecast ip: ->(ip) { IPAddr.new(ip) },
|
9
|
+
created_at: ->(date) { DateTime.iso8601(date) },
|
10
|
+
checked_at: ->(date) { DateTime.iso8601(date) },
|
11
|
+
updated_at: ->(date) { DateTime.iso8601(date) },
|
12
|
+
state_changed_at: ->(date) { DateTime.iso8601(date) }
|
13
|
+
|
14
|
+
def ipv4?
|
15
|
+
ip.ipv4?
|
16
|
+
end
|
17
|
+
|
18
|
+
def ipv6?
|
19
|
+
ip.ipv6?
|
20
|
+
end
|
21
|
+
|
22
|
+
def valid?
|
23
|
+
state == 'valid'
|
24
|
+
end
|
25
|
+
|
26
|
+
def invalid?
|
27
|
+
state == 'invalid'
|
28
|
+
end
|
29
|
+
|
30
|
+
def age_minutes
|
31
|
+
t1 = Time.now.to_i
|
32
|
+
t2 = checked_at.to_i
|
33
|
+
seconds_since_check = t1 - t2
|
34
|
+
minutes_since_check = seconds_since_check / 60
|
35
|
+
minutes_since_check
|
36
|
+
end
|
37
|
+
end
|
metadata
ADDED
@@ -0,0 +1,125 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: globetrotter
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.4
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Nick Lopez
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2014-05-18 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.6'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.6'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rubydns
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0.8'
|
48
|
+
type: :runtime
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0.8'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: trollop
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '2.0'
|
62
|
+
type: :runtime
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '2.0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: wrest
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - "~>"
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '1.5'
|
76
|
+
type: :runtime
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - "~>"
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '1.5'
|
83
|
+
description:
|
84
|
+
email:
|
85
|
+
- nlopez@amplify.com
|
86
|
+
executables:
|
87
|
+
- globetrotter
|
88
|
+
extensions: []
|
89
|
+
extra_rdoc_files: []
|
90
|
+
files:
|
91
|
+
- ".gitignore"
|
92
|
+
- Gemfile
|
93
|
+
- LICENSE.txt
|
94
|
+
- README.md
|
95
|
+
- Rakefile
|
96
|
+
- bin/globetrotter
|
97
|
+
- globetrotter.gemspec
|
98
|
+
- lib/globetrotter.rb
|
99
|
+
- lib/globetrotter/nameserver.rb
|
100
|
+
- lib/globetrotter/version.rb
|
101
|
+
homepage: https://github.com/amplify-education/globetrotter
|
102
|
+
licenses:
|
103
|
+
- MIT
|
104
|
+
metadata: {}
|
105
|
+
post_install_message:
|
106
|
+
rdoc_options: []
|
107
|
+
require_paths:
|
108
|
+
- lib
|
109
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
110
|
+
requirements:
|
111
|
+
- - ">="
|
112
|
+
- !ruby/object:Gem::Version
|
113
|
+
version: '0'
|
114
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
115
|
+
requirements:
|
116
|
+
- - ">="
|
117
|
+
- !ruby/object:Gem::Version
|
118
|
+
version: '0'
|
119
|
+
requirements: []
|
120
|
+
rubyforge_project:
|
121
|
+
rubygems_version: 2.2.2
|
122
|
+
signing_key:
|
123
|
+
specification_version: 4
|
124
|
+
summary: Resolve DNS records at many different nameservers all over the world.
|
125
|
+
test_files: []
|