Skip to content

Instantly share code, notes, and snippets.

@rys
Created March 16, 2012 01:29
Show Gist options
  • Save rys/2048059 to your computer and use it in GitHub Desktop.
Save rys/2048059 to your computer and use it in GitHub Desktop.
simple DNS record finder plugin for rbot
require 'domain_info.rb'
class ExtendedDomainInfoPlugin < Plugin
def help(plugin, topic="")
"!edi domain [ip,ptr,spf,all]"
end
def edi_get_all(domain)
s = ''
begin
dns = Resolv::DNS.new
dns.getresources(domain, Resolv::DNS::Resource::IN::ANY).collect do |r|
if r.kind_of?(Resolv::DNS::Resource::IN::MX) then
s += "\nMX: #{r.exchange.to_s.strip}"
end
if r.kind_of?(Resolv::DNS::Resource::IN::NS) then
s += "\nNS: #{r.name.to_s.strip}"
end
if r.kind_of?(Resolv::DNS::Resource::IN::A) then
s += "\nA: #{r.address.to_s.strip}"
end
if r.kind_of?(Resolv::DNS::Resource::IN::TXT) then
r.strings.each do |q|
s += "\nTXT: #{q.strip}"
end
end
if r.kind_of?(Resolv::DNS::Resource::IN::CNAME) then
s += "\nCNAME: #{r.name.to_s.strip}"
end
if r.kind_of?(Resolv::DNS::Resource::IN::SOA) then
h = r.expire / 3600
t = r.retry / 3600
s += "\nSOA: #{r.serial.to_s.strip} #{r.rname.to_s.strip} expires:#{h.to_s.strip}hrs retries:#{t.to_s.strip}hrs"
end
if r.kind_of?(Resolv::DNS::Resource::IN::AAAA) then
s += "\nAAAA: #{r.address.to_s.strip}"
end
end
rescue Exception => e
s = "edi error: " + e.message
end
s.strip
end
def edi(m, params)
begin
domain = params[:domain]
bit = params[:bit]
d = DomainInfo::Domain.new(domain.strip)
case bit.downcase.strip
when 'ip' then m.reply d.ip
when 'ptr' then m.reply d.ptr.value
when 'spf' then m.reply d.spf.value
when 'all' then m.reply edi_get_all(domain)
end
rescue Exception => e
m.reply "edi error: #{e.message}"
end
end
end
plugin = ExtendedDomainInfoPlugin.new
plugin.map 'edi :domain :bit',
:defaults => { :domain => 'pixeltards.com', :bit => 'ip' },
:thread => true
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment