summaryrefslogtreecommitdiff
path: root/data/rbot/plugins/nslookup.rb
diff options
context:
space:
mode:
authorTom Gilbert <tom@linuxbrit.co.uk>2005-07-29 13:44:33 +0000
committerTom Gilbert <tom@linuxbrit.co.uk>2005-07-29 13:44:33 +0000
commit676dd61e6b0bea5f506d064039a685944aefd6fb (patch)
tree60fa1936a11a67d6412f9db28532d623aabed5d1 /data/rbot/plugins/nslookup.rb
parent438d56ceb82755961229d222d82a1c22ce04ab1d (diff)
Fri Jul 29 13:07:56 BST 2005 Tom Gilbert <tom@linuxbrit.co.uk>
* Moved some stuff out of util.rb into the plugins that actually need them. Those methods didn't belong in util as they were plugin-specific. * moved a few more plugins to use map() where appropriate * made the url plugin only store unique urls
Diffstat (limited to 'data/rbot/plugins/nslookup.rb')
-rw-r--r--data/rbot/plugins/nslookup.rb71
1 files changed, 29 insertions, 42 deletions
diff --git a/data/rbot/plugins/nslookup.rb b/data/rbot/plugins/nslookup.rb
index 92da1ba7..160fee85 100644
--- a/data/rbot/plugins/nslookup.rb
+++ b/data/rbot/plugins/nslookup.rb
@@ -1,56 +1,43 @@
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
+ require 'resolv'
+ def gethostname(address)
+ Resolv.getname(address)
+ end
+ def getaddresses(name)
+ Resolv.getaddresses(name)
end
def help(plugin, topic="")
- "nslookup|dns <hostname|ip> => show local resolution results for hostname or ip address"
+ "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
+
+ def name_to_ip(m, params)
+ Thread.new do
+ begin
+ a = getaddresses(params[:host])
+ if a.length > 0
+ m.reply m.params + ": " + a.join(", ")
+ else
+ m.reply "#{params[:host]}: not found"
+ end
+ rescue StandardError => err
+ m.reply "#{params[:host]}: not found"
+ end
end
+ end
+
+ def ip_to_name(m, params)
Thread.new do
- if(m.params =~ /^\d+\.\d+\.\d+\.\d+$/)
begin
- a = gethostname(m.params)
+ a = gethostname(params[:ip])
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"
+ m.reply "#{params[:ip]}: not found (does not reverse resolve)"
end
- else
- m.reply "incorrect usage: " + help(m.plugin)
- end
- end
+ end
end
end
plugin = DnsPlugin.new
-plugin.register("nslookup")
-plugin.register("dns")
+plugin.map 'dns :ip', :action => 'ip_to_name',
+ :requirements => {:ip => /^\d+\.\d+\.\d+\.\d+$/}
+plugin.map 'dns :host', :action => 'name_to_ip'