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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 0b7bac2931e731855c7f89ec0b6957031ba9d65ebea0e030df7224986ace9a25
4
- data.tar.gz: 437fdbeece0d4517d39c0017c7207b395c804ed224fa0dd6820407db45235fb0
3
+ metadata.gz: 39fc3cbc3ac6a57ae2bdef218ed12d1078903713622b1f333e60fe0c3ea15f0b
4
+ data.tar.gz: 73b7f165fc5bdf37ec4ebc1fb55bda75948b03596176f6e383c4f4dbad0b25b0
5
5
  SHA512:
6
- metadata.gz: cc5732efa9139bcddba08bfc5f78ec5bad3880b253abe972bba869d3d75e8de4b70cf9eecf25dcb57c56e460a3d70893aed2b3eb4696a6e277aaefec579bd8af
7
- data.tar.gz: e6cd0c9ca267d08d02c10865b27cf13fcacde426b63876582a41d488f995be9fa31944df86524eb2148a66beabd6f0d7e02397e4c33b6cda9bd2064048c91283
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
- console help [COMMAND] # Describe available commands or one specific command
50
- console resolve [NAME] # resolve a given name
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
@@ -8,6 +8,8 @@ require "doh_client/client/base"
8
8
  require "doh_client/client/cloudflare"
9
9
  require "doh_client/client/google"
10
10
 
11
+ require "doh_client/server"
12
+
11
13
  require "doh_client/cli"
12
14
 
13
15
  module DoHClient
@@ -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
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module DoHClient
4
- VERSION = "0.1.1"
4
+ VERSION = "0.2.0"
5
5
  end
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.1.1
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: