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)
17 a = getaddresses(params[:host])
19 m.reply m.params + ": " + a.join(", ")
21 m.reply "#{params[:host]}: not found"
23 rescue StandardError => err
24 m.reply "#{params[:host]}: not found"
29 def ip_to_name(m, params)
32 a = gethostname(params[:ip])
33 m.reply m.params + ": " + a if a
34 rescue StandardError => err
35 m.reply "#{params[:ip]}: not found (does not reverse resolve)"
40 plugin = DnsPlugin.new
41 plugin.map 'dns :ip', :action => 'ip_to_name',
42 :requirements => {:ip => /^\d+\.\d+\.\d+\.\d+$/}
43 plugin.map 'dns :host', :action => 'name_to_ip'