]> Pileus Git - ~andy/rhawk/commitdiff
Add GeoIP Lookup
authorAndy Spencer <andy753421@gmail.com>
Sun, 18 May 2014 06:48:54 +0000 (06:48 +0000)
committerAndy Spencer <andy753421@gmail.com>
Sun, 18 May 2014 06:52:12 +0000 (06:52 +0000)
rhawk

diff --git a/rhawk b/rhawk
index 21b6b20574c1454c04b54488147086661cddc515..f68c93f453e463b44d5aba679fccff19f47a6c4a 100755 (executable)
--- a/rhawk
+++ b/rhawk
@@ -187,6 +187,26 @@ BEGIN {
                say("no auth info for " _who)
 }
 
+# GeoIP Lookup
+function geoip(ip,  dat, cmd, line, parts) {
+       dat = "/usr/share/GeoIP/GeoIPCity.dat"
+
+       cmd = "geoiplookup -f " dat " " ip
+       cmd | getline line
+       close(cmd)
+
+       if (split(line, parts, /[:,] /) >= 9)
+               return parts[8] ","  parts[9] " -- " \
+                      parts[6] ", " parts[4] ", " parts[3] " -- " ip
+       else
+               return "not found -- " ip
+}
+
+/^\.geoip (([0-9a-zA-Z_.-]+) *)*$/ {
+       for (_i=2; _i<=NF; _i++)
+               say(geoip($_i))
+}
+
 # Fortune
 TO == NICK && /^/               { extra = ""   }
 TO == NICK && /^\.?fortune.*-o/ { extra = "-o" }