|
|
@@ -1,8 +1,53 @@
|
|
|
# host.tcl
|
|
|
+#
|
|
|
+# This script resolves host names or ip addresses using the tool "host" with
|
|
|
+# the !host command.
|
|
|
+#
|
|
|
+# Usage:
|
|
|
+# !host name|ip resolve name or ip address
|
|
|
+#
|
|
|
+# Enable for a channel with: .chanset #channel +host
|
|
|
+# Disable for a channel with: .chanset #channel -host
|
|
|
|
|
|
-proc host_lookup { nick host hand chan arg } {
|
|
|
- set output [exec host [lindex $arg 0]]
|
|
|
- puthelp "PRIVMSG $chan :[lrange $output 0 end]"
|
|
|
+# tested versions, might run on earlier versions
|
|
|
+package require Tcl 8.6
|
|
|
+package require eggdrop 1.8.4
|
|
|
+
|
|
|
+namespace eval ::host {
|
|
|
+ # channel flag for enabling/disabling
|
|
|
+ setudef flag host
|
|
|
+
|
|
|
+ # path to host tool
|
|
|
+ variable hostCmd "/usr/bin/host"
|
|
|
}
|
|
|
|
|
|
-bind pub - !host host_lookup
|
|
|
+proc ::host::lookup { nick host hand chan arg } {
|
|
|
+ variable hostCmd
|
|
|
+
|
|
|
+ # check channel flag if enabled in this channel
|
|
|
+ if {![channel get $chan host]} {
|
|
|
+ return 0
|
|
|
+ }
|
|
|
+
|
|
|
+ # check if hostname/ip parameter is given
|
|
|
+ if {$arg == ""} {
|
|
|
+ return 0
|
|
|
+ }
|
|
|
+
|
|
|
+ # run host and capture output
|
|
|
+ if {[catch {exec $hostCmd [lindex $arg 0]} output]} {
|
|
|
+ putlog "Error executing $hostCmd: $output"
|
|
|
+ return 0
|
|
|
+ }
|
|
|
+
|
|
|
+ # send every output line as a message
|
|
|
+ foreach i [split $output "\n"] {
|
|
|
+ puthelp "PRIVMSG $chan :$i"
|
|
|
+ }
|
|
|
+ return 1
|
|
|
+}
|
|
|
+
|
|
|
+namespace eval ::host {
|
|
|
+ bind pub - !host ::host::lookup
|
|
|
+ putlog "Loaded host.tcl"
|
|
|
+}
|