Slide 25
Slide 25 text
spf-query 使ってみる
require 'bundler/inline'
gemfile do
source 'https://rubygems.org'
gem 'spf-query'
end
domain = ARGV.first
q = SPF::Query::Record.query(domain)
def query(q, lookup_count)
q.mechanisms.each do |mechanism|
case mechanism.name
when :ip4, :ip6
puts mechanism.value
when :include, :redirect
lookup_count += 1
return if lookup_count > 10
puts ">>" + mechanism.value
# _spf
サブドメインを暗黙的に引いてしまうらしい
# https://github.com/trailofbits/spf-query/issues/10
records = Resolv::DNS.new.getresources(mechanism.value,
Resolv::DNS::Resource::IN::TXT)
spf_record = records.find do |record|
record.strings.join.include?('v=spf1')
end
spf_record_value = spf_record.strings.join
q = SPF::Query::Parser.parse(spf_record_value)
query(q, lookup_count)
when :a
lookup_count += 1
# Resolv::DNS::Resource::IN::A
でレコードを引く
when :mx
lookup_count += 1
# Resolv::DNS::Resource::IN::MX
でレコードを引く
when :ptr, :exsists
lookup_count += 1
#
頑張って実装
end
end
end
query(q, 0) 25