Skip to content

Instantly share code, notes, and snippets.

@flano-yuki
Last active Jan 12, 2018
Embed
What would you like to do?
require 'net/dns'
require 'optparse'
require 'net/https'
require 'base64'
require 'uri'
endpoint = ""
opt = OptionParser.new
opt.on('-s endpoint') {|v| endpoint = v }
argv = opt.parse(ARGV)
domain = argv[0]
type = argv[1] || "A"
query = Net::DNS::Packet.new(domain, type)
row_query = Base64.urlsafe_encode64(query.data).delete('=')
res = Net::HTTP.get(URI.parse("#{endpoint}?ct&body=#{row_query}"))
puts Net::DNS::Packet::parse(res)
@flano-yuki
Copy link
Author

flano-yuki commented Jan 11, 2018

vagrant:~$ ruby ./doh-client.rb "asnokaze.com" A -s 'https://dns.google.com/experimental'
;; HEADER SECTION
;; id = 2137
;; qr = 1       opCode: QUERY   aa = 0  tc = 0  rd = 1
;; ra = 1       ad = 0  cd = 0  rcode = NoError
;; qdCount = 1  anCount = 1     nsCount = 0     arCount = 0

;; QUESTION SECTION (1 record):
;; asnokaze.com.                IN      A       

;; ANSWER SECTION (1 record):
asnokaze.com.           3599    IN      A       160.16.124.39

@flano-yuki
Copy link
Author

手前味噌ですが、DNS over HTTPSの仕様の解説は
http://asnokaze.hatenablog.com/entry/2017/09/14/015154

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment