Created
July 1, 2014 12:16
-
-
Save yteraoka/ce80d379b0d3a1e4b26a to your computer and use it in GitHub Desktop.
SPF record の ip4 部分を再帰的に取り出す
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#! /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