1 class DnsPlugin < Plugin
3 require 'resolv-replace'
4 def gethostname(address)
5 Resolv.getname(address)
8 Resolv.getaddresses(name)
11 def gethostname(address)
12 Socket.gethostbyname(address).first
14 def getaddresses(name)
15 a = Socket.gethostbyname(name)
16 list = Socket.getaddrinfo(a[0], 'http')
25 def help(plugin, topic="")
26 "nslookup|dns <hostname|ip> => show local resolution results for hostname or ip address"
30 m.reply "incorrect usage: " + help(m.plugin)
34 if(m.params =~ /^\d+\.\d+\.\d+\.\d+$/)
36 a = gethostname(m.params)
37 m.reply m.params + ": " + a if a
38 rescue StandardError => err
39 m.reply "#{m.params}: not found"
41 elsif(m.params =~ /^\S+$/)
43 a = getaddresses(m.params)
44 m.reply m.params + ": " + a.join(", ")
45 rescue StandardError => err
46 m.reply "#{m.params}: not found"
49 m.reply "incorrect usage: " + help(m.plugin)
54 plugin = DnsPlugin.new
55 plugin.register("nslookup")
56 plugin.register("dns")