From 0f3e302547363ea237454dda891ddb5de1be4476 Mon Sep 17 00:00:00 2001 From: Tom Gilbert Date: Sat, 9 Oct 2004 01:51:05 +0000 Subject: initial import of rbot --- rbot/plugins/nslookup.rb | 56 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 56 insertions(+) create mode 100644 rbot/plugins/nslookup.rb (limited to 'rbot/plugins/nslookup.rb') diff --git a/rbot/plugins/nslookup.rb b/rbot/plugins/nslookup.rb new file mode 100644 index 00000000..a68f0ee8 --- /dev/null +++ b/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 => 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 =~ /^(\w|\.)+$/) + 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") -- cgit v1.2.3