1 class DnsPlugin < Plugin
3 def gethostname(address)
4 Resolv.getname(address)
7 Resolv.getaddresses(name)
10 def help(plugin, topic="")
11 "dns <hostname|ip> => show local resolution results for hostname or ip address"
14 def name_to_ip(m, params)
16 a = getaddresses(params[:host])
18 m.reply m.params + ": " + a.join(", ")
20 m.reply "#{params[:host]}: not found"
22 rescue StandardError => err
23 m.reply "#{params[:host]}: not found"
27 def ip_to_name(m, params)
29 a = gethostname(params[:ip])
30 m.reply m.params + ": " + a if a
31 rescue StandardError => err
32 m.reply "#{params[:ip]}: not found (does not reverse resolve)"
36 plugin = DnsPlugin.new
37 plugin.map 'dns :ip', :action => 'ip_to_name', :thread => true,
38 :requirements => {:ip => /^\d+\.\d+\.\d+\.\d+$/}
39 plugin.map 'dns :host', :action => 'name_to_ip', :thread => true