]> git.netwichtig.de Git - user/henk/code/ruby/rbot.git/blob - data/rbot/plugins/nslookup.rb
92da1ba779e2f4250d219cc5155a68d503278b6e
[user/henk/code/ruby/rbot.git] / data / rbot / plugins / nslookup.rb
1 class DnsPlugin < Plugin
2   begin
3     require 'resolv-replace'
4     def gethostname(address)
5       Resolv.getname(address)
6     end
7     def getaddresses(name)
8       Resolv.getaddresses(name)
9     end
10   rescue LoadError
11     def gethostname(address)
12       Socket.gethostbyname(address).first
13     end
14     def getaddresses(name)
15       a = Socket.gethostbyname(name)
16       list = Socket.getaddrinfo(a[0], 'http')
17       addresses = Array.new
18       list.each {|line|
19        addresses << line[3]
20       }
21       addresses
22     end
23   end
24
25   def help(plugin, topic="")
26     "nslookup|dns <hostname|ip> => show local resolution results for hostname or ip address"
27   end
28   def privmsg(m)
29     unless(m.params)
30       m.reply "incorrect usage: " + help(m.plugin)
31       return
32     end
33     Thread.new do
34       if(m.params =~ /^\d+\.\d+\.\d+\.\d+$/)
35        begin
36          a = gethostname(m.params)
37          m.reply m.params + ": " + a if a
38        rescue StandardError => err
39          m.reply "#{m.params}: not found"
40        end
41       elsif(m.params =~ /^\S+$/)
42        begin
43          a = getaddresses(m.params)
44          m.reply m.params + ": " + a.join(", ")
45        rescue StandardError => err
46          m.reply "#{m.params}: not found"
47        end
48       else
49        m.reply "incorrect usage: " + help(m.plugin)
50       end
51     end
52   end
53 end
54 plugin = DnsPlugin.new
55 plugin.register("nslookup")
56 plugin.register("dns")