Skip to content

Instantly share code, notes, and snippets.

@ikaruga777
Last active March 6, 2024 10:57
Show Gist options
  • Save ikaruga777/2621e39c09396a3aa989d02a02617f5c to your computer and use it in GitHub Desktop.
Save ikaruga777/2621e39c09396a3aa989d02a02617f5c to your computer and use it in GitHub Desktop.
SPFレコードからIP拾ってくるくん
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
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)
@ikaruga777
Copy link
Author

$ ruby parse_spf.rb _spf.google.com
>>_netblocks.google.com
35.190.247.0/24
64.233.160.0/19
66.102.0.0/20
66.249.80.0/20
72.14.192.0/18
74.125.0.0/16
108.177.8.0/21
173.194.0.0/16
209.85.128.0/17
216.58.192.0/19
216.239.32.0/19
>>_netblocks2.google.com
2001:4860:4000::/36
2404:6800:4000::/36
2607:f8b0:4000::/36
2800:3f0:4000::/36
2a00:1450:4000::/36
2c0f:fb50:4000::/36
>>_netblocks3.google.com
172.217.0.0/19
172.217.32.0/20
172.217.128.0/19
172.217.160.0/20
172.217.192.0/19
172.253.56.0/21
172.253.112.0/20
108.177.96.0/19
35.191.0.0/16
130.211.0.0/22
$ ruby parse_spf.rb shop-pro.jp
210.152.224.0/25
>>mail.zendesk.com
103.151.192.0/23
185.12.80.0/22
188.172.128.0/20
192.161.144.0/20
216.198.0.0/18
>>fc99251.cuenote.jp
210.152.204.173
210.152.204.174/31
210.152.204.176/30
210.152.204.180/31
>>spf001.shop-pro.jp
>>spf-internal.shop-pro.jp
210.172.160.0/24
210.172.182.0/24
210.232.1.0/25
210.170.99.0/25
210.157.19.0/24
210.154.147.64/26
157.7.180.0/27
157.7.180.160/27
133.130.34.0/23
163.44.191.0/24
>>spf-external.shop-pro.jp
210.175.7.1/32
>>srs0260.cuenote.jp
210.152.207.201
210.152.207.202
210.152.207.203
>>aspmx.pardot.com
>>et._spf.pardot.com
198.245.81.0/24
136.147.176.0/24
13.111.0.0/16
136.147.182.0/24
136.147.135.0/24
199.122.123.0/24

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