]> git.netwichtig.de Git - user/henk/code/ruby/rbot.git/commitdiff
iplookup plugin: support IPv6 too
authorGiuseppe Bilotta <giuseppe.bilotta@gmail.com>
Sun, 3 Aug 2008 08:03:36 +0000 (10:03 +0200)
committerGiuseppe Bilotta <giuseppe.bilotta@gmail.com>
Sun, 3 Aug 2008 08:05:33 +0000 (10:05 +0200)
This is achieved by moving the check for IP vs hostname in the
iplookup() method itself, and using the existing regexps to check if a
string is an IP or not.

data/rbot/plugins/iplookup.rb

index 87c94699fa9c9d3f42ab1ae21f712a35bd4c6140..a53b16e470f148c74045e5d11001c26a52bd898f 100644 (file)
@@ -188,8 +188,10 @@ class IPLookupPlugin < Plugin
   end
 
   def iplookup(m, params)
-    reply = ""
-    if params[:domain]
+    debug params
+    if params[:domain].match(/^#{Regexp::Irc::HOSTADDR}$/)
+      ip = params[:domain]
+    else
       begin
         ip = Resolv.getaddress(params[:domain])
         reply += "#{params[:domain]} | "
@@ -197,8 +199,6 @@ class IPLookupPlugin < Plugin
         m.reply "#{e.message}"
         return
       end
-    else
-      ip = params[:ip]
     end
 
     reply += ArinWhois.lookup_info(ip)
@@ -214,8 +214,7 @@ class IPLookupPlugin < Plugin
 end
 
 plugin = IPLookupPlugin.new
-plugin.map 'iplookup :ip', :action => 'iplookup', :requirements => {:ip => /^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}$/}, :thread => true
-plugin.map 'iplookup :domain', :action => 'iplookup', :requirements => {:domain => /^[a-z0-9\.\-]{4,255}$/i}, :thread => true
+plugin.map 'iplookup :domain', :action => 'iplookup', :thread => true
 plugin.map 'userip :user', :action => 'userip', :requirements => {:user => /\w+/}, :thread => true