Skip to content

Instantly share code, notes, and snippets.

@yteraoka
Created July 1, 2014 12:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save yteraoka/ce80d379b0d3a1e4b26a to your computer and use it in GitHub Desktop.
Save yteraoka/ce80d379b0d3a1e4b26a to your computer and use it in GitHub Desktop.
SPF record の ip4 部分を再帰的に取り出す
#! /usr/bin/env ruby
#****************************************************************************
#
# Usage: spfaddr.rb <domain>
#
# spfaddr.rb _spf.google.com
#
#****************************************************************************
require 'dnsruby'
def spfaddr(domain)
res = Dnsruby::Resolver.new
res.nameservers = ['8.8.8.8', '8.8.4.4']
ret = res.query(domain, Dnsruby::Types.TXT)
ret.each_answer do |a|
if a.data.match('v=spf')
a.data.split(/\s+/).each do |atom|
if atom.gsub!(/^ip4:/, '')
puts atom
elsif atom.gsub!(/^include:/, '')
spfaddr(atom)
end
end
end
end
end
spfaddr(ARGV[0])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment