doh_client 0.1.1 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +8 -4
- data/doh_client.gemspec +2 -0
- data/lib/doh_client.rb +2 -0
- data/lib/doh_client/cli.rb +16 -0
- data/lib/doh_client/server.rb +33 -0
- data/lib/doh_client/version.rb +1 -1
- metadata +30 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 39fc3cbc3ac6a57ae2bdef218ed12d1078903713622b1f333e60fe0c3ea15f0b
|
4
|
+
data.tar.gz: 73b7f165fc5bdf37ec4ebc1fb55bda75948b03596176f6e383c4f4dbad0b25b0
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f2720b92c65401f621aa41a30694e876c19e4b2427c5744534581418551cadaaa93c7a52a02e4a6111e915fb60cfb37c86fb3175f99c6be385b44b62d5c58c35
|
7
|
+
data.tar.gz: 9a84d7da0f96a247dff2d1d9d4cf7be2e060807e43cadfe9840656d2c6f4d62dd5f0cc02b860e0a5bd919d93b76ce83e14af3fac6eea4124d5dcd6841151fa4b
|
data/README.md
CHANGED
@@ -4,7 +4,7 @@
|
|
4
4
|
[![Maintainability](https://api.codeclimate.com/v1/badges/e9119ee2021f1cfb895d/maintainability)](https://codeclimate.com/github/ninoseki/doh_client/maintainability)
|
5
5
|
[![Coverage Status](https://coveralls.io/repos/github/ninoseki/doh_client/badge.svg?branch=master)](https://coveralls.io/github/ninoseki/doh_client?branch=master)
|
6
6
|
|
7
|
-
DNS over HTTPS(DoH) client for Ruby
|
7
|
+
DNS over HTTPS (DoH) client for Ruby
|
8
8
|
|
9
9
|
## Installation
|
10
10
|
|
@@ -46,14 +46,18 @@ DoHClient::Cloudflare.resolve("example.com", { type: "A", do: true, cd: false })
|
|
46
46
|
```bash
|
47
47
|
$ doh_client
|
48
48
|
Commands:
|
49
|
-
|
50
|
-
|
49
|
+
doh_client act_as_server # act as a local DNS server on a given port (default: 5300)
|
50
|
+
doh_client help [COMMAND] # Describe available commands or one specific command
|
51
|
+
doh_client resolve [NAME] # resolve a given name
|
51
52
|
|
52
53
|
Options:
|
53
54
|
[--resolver=RESOLVER] # a resolver to use ('google' or 'cloudflare', default: google)
|
54
55
|
|
55
56
|
$ doh_client resolve example.com --type A
|
56
|
-
# => {"Status":0,"TC":false,"RD":true,"RA":true,"AD":true,"CD":false,"Question":[{"name":"example.com.","type":1}],"Answer":[{"name":"example.com.","type":1,"TTL":5169,"data":"93.184.216.34"}]
|
57
|
+
# => {"Status":0,"TC":false,"RD":true,"RA":true,"AD":true,"CD":false,"Question":[{"name":"example.com.","type":1}],"Answer":[{"name":"example.com.","type":1,"TTL":5169,"data":"93.184.216.34"}]
|
58
|
+
|
59
|
+
$ doh_client act_as_server
|
60
|
+
# => Starting DNS server 0.0.0.0:5300 (tcp/udp)
|
57
61
|
```
|
58
62
|
|
59
63
|
## License
|
data/doh_client.gemspec
CHANGED
@@ -24,6 +24,7 @@ Gem::Specification.new do |spec|
|
|
24
24
|
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
25
25
|
spec.require_paths = ["lib"]
|
26
26
|
|
27
|
+
spec.add_development_dependency "async-rspec", "~> 1.11"
|
27
28
|
spec.add_development_dependency "bundler", "~> 1.16"
|
28
29
|
spec.add_development_dependency "coveralls", "~> 0.8"
|
29
30
|
spec.add_development_dependency "rake", "~> 12.3"
|
@@ -31,6 +32,7 @@ Gem::Specification.new do |spec|
|
|
31
32
|
spec.add_development_dependency "vcr", "~> 4.0"
|
32
33
|
spec.add_development_dependency "webmock", "~> 3.4"
|
33
34
|
|
35
|
+
spec.add_dependency "async-dns", "~> 1.2"
|
34
36
|
spec.add_dependency "http", "~> 3.3"
|
35
37
|
spec.add_dependency "thor", "~> 0.19"
|
36
38
|
end
|
data/lib/doh_client.rb
CHANGED
data/lib/doh_client/cli.rb
CHANGED
@@ -18,6 +18,22 @@ module DoHClient
|
|
18
18
|
puts hash.to_json
|
19
19
|
end
|
20
20
|
|
21
|
+
desc "act_as_server", "act as a local DNS server on a given port (default: 5300)"
|
22
|
+
method_option :port, type: :numeric, default: 5300
|
23
|
+
def act_as_server
|
24
|
+
port = options[:port]
|
25
|
+
interfaces = [[:udp, "0.0.0.0", port], [:tcp, "0.0.0.0", port]]
|
26
|
+
server = DoHClient::Server.new(interfaces)
|
27
|
+
puts "Starting DNS server 0.0.0.0:#{port} (tcp/udp)"
|
28
|
+
begin
|
29
|
+
server.run
|
30
|
+
rescue Interrupt
|
31
|
+
puts "\nStopping DNS server..."
|
32
|
+
ensure
|
33
|
+
puts "Stopped"
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
21
37
|
no_commands do
|
22
38
|
def resolver
|
23
39
|
case options[:resolver]
|
@@ -0,0 +1,33 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'async/dns'
|
4
|
+
|
5
|
+
module DoHClient
|
6
|
+
class Server < Async::DNS::Server
|
7
|
+
attr_reader :client
|
8
|
+
def initialize(resolver)
|
9
|
+
super
|
10
|
+
@client = resolver == "cloudflare" ? DoHClient::Client::Cloudflare : DoHClient::Client::Google
|
11
|
+
end
|
12
|
+
|
13
|
+
def process(name, resource_class, transaction)
|
14
|
+
type = resource_class.to_s.split('::').last
|
15
|
+
|
16
|
+
begin
|
17
|
+
response = client.resolve(name, type: type)
|
18
|
+
rescue ResponseError => _
|
19
|
+
return transaction.fail!(:NXDomain) unless answers
|
20
|
+
end
|
21
|
+
|
22
|
+
answers = response["Answer"]
|
23
|
+
return transaction.fail!(:NXDomain) unless answers
|
24
|
+
|
25
|
+
transaction.append_question!
|
26
|
+
answers.each do |answer|
|
27
|
+
next unless klass = Resolv::DNS::Resource.get_class(answer["type"], resource_class::ClassValue)
|
28
|
+
resource = klass < Resolv::DNS::Resource::DomainName ? klass.new(Resolv::DNS::Name.create(answer["data"])) : klass.new(answer["data"])
|
29
|
+
transaction.response.add_answer(answer["name"], answer["TTL"], resource)
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
data/lib/doh_client/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: doh_client
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Manabu Niseki
|
@@ -10,6 +10,20 @@ bindir: exe
|
|
10
10
|
cert_chain: []
|
11
11
|
date: 2018-08-26 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: async-rspec
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.11'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.11'
|
13
27
|
- !ruby/object:Gem::Dependency
|
14
28
|
name: bundler
|
15
29
|
requirement: !ruby/object:Gem::Requirement
|
@@ -94,6 +108,20 @@ dependencies:
|
|
94
108
|
- - "~>"
|
95
109
|
- !ruby/object:Gem::Version
|
96
110
|
version: '3.4'
|
111
|
+
- !ruby/object:Gem::Dependency
|
112
|
+
name: async-dns
|
113
|
+
requirement: !ruby/object:Gem::Requirement
|
114
|
+
requirements:
|
115
|
+
- - "~>"
|
116
|
+
- !ruby/object:Gem::Version
|
117
|
+
version: '1.2'
|
118
|
+
type: :runtime
|
119
|
+
prerelease: false
|
120
|
+
version_requirements: !ruby/object:Gem::Requirement
|
121
|
+
requirements:
|
122
|
+
- - "~>"
|
123
|
+
- !ruby/object:Gem::Version
|
124
|
+
version: '1.2'
|
97
125
|
- !ruby/object:Gem::Dependency
|
98
126
|
name: http
|
99
127
|
requirement: !ruby/object:Gem::Requirement
|
@@ -148,6 +176,7 @@ files:
|
|
148
176
|
- lib/doh_client/client/google.rb
|
149
177
|
- lib/doh_client/client/request.rb
|
150
178
|
- lib/doh_client/error.rb
|
179
|
+
- lib/doh_client/server.rb
|
151
180
|
- lib/doh_client/version.rb
|
152
181
|
homepage: https://github.com/ninoseki/doh_client
|
153
182
|
licenses:
|