diff options
author | Tom Gilbert <tom@linuxbrit.co.uk> | 2005-07-27 15:59:13 +0000 |
---|---|---|
committer | Tom Gilbert <tom@linuxbrit.co.uk> | 2005-07-27 15:59:13 +0000 |
commit | 21949774b91eaec6ecde4eaa8ad121e2c0a36b87 (patch) | |
tree | 41a7601e168018ac203bad7ca8d7f9f82515bc28 /data/rbot/plugins/nslookup.rb | |
parent | 51cf09ec02d089bfdd80e5f728cfc92a234dc437 (diff) |
rearrange repo for packaging
Diffstat (limited to 'data/rbot/plugins/nslookup.rb')
-rw-r--r-- | data/rbot/plugins/nslookup.rb | 56 |
1 files changed, 56 insertions, 0 deletions
diff --git a/data/rbot/plugins/nslookup.rb b/data/rbot/plugins/nslookup.rb new file mode 100644 index 00000000..92da1ba7 --- /dev/null +++ b/data/rbot/plugins/nslookup.rb @@ -0,0 +1,56 @@ +class DnsPlugin < Plugin + begin + require 'resolv-replace' + def gethostname(address) + Resolv.getname(address) + end + def getaddresses(name) + Resolv.getaddresses(name) + end + rescue LoadError + def gethostname(address) + Socket.gethostbyname(address).first + end + def getaddresses(name) + a = Socket.gethostbyname(name) + list = Socket.getaddrinfo(a[0], 'http') + addresses = Array.new + list.each {|line| + addresses << line[3] + } + addresses + end + end + + def help(plugin, topic="") + "nslookup|dns <hostname|ip> => show local resolution results for hostname or ip address" + end + def privmsg(m) + unless(m.params) + m.reply "incorrect usage: " + help(m.plugin) + return + end + Thread.new do + if(m.params =~ /^\d+\.\d+\.\d+\.\d+$/) + begin + a = gethostname(m.params) + m.reply m.params + ": " + a if a + rescue StandardError => err + m.reply "#{m.params}: not found" + end + elsif(m.params =~ /^\S+$/) + begin + a = getaddresses(m.params) + m.reply m.params + ": " + a.join(", ") + rescue StandardError => err + m.reply "#{m.params}: not found" + end + else + m.reply "incorrect usage: " + help(m.plugin) + end + end + end +end +plugin = DnsPlugin.new +plugin.register("nslookup") +plugin.register("dns") |