host.tcl 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. # host.tcl
  2. #
  3. # This script resolves host names or ip addresses using the tool "host" with
  4. # the !host command.
  5. #
  6. # Usage:
  7. # !host name|ip resolve name or ip address
  8. #
  9. # Enable for a channel with: .chanset #channel +host
  10. # Disable for a channel with: .chanset #channel -host
  11. # tested versions, might run on earlier versions
  12. package require Tcl 8.6
  13. package require eggdrop 1.8.4
  14. namespace eval ::host {
  15. # channel flag for enabling/disabling
  16. setudef flag host
  17. # path to host tool
  18. variable hostCmd "/usr/bin/host"
  19. }
  20. proc ::host::lookup { nick host hand chan arg } {
  21. variable hostCmd
  22. # check channel flag if enabled in this channel
  23. if {![channel get $chan host]} {
  24. return 0
  25. }
  26. # check if hostname/ip parameter is given
  27. if {$arg == ""} {
  28. return 0
  29. }
  30. # run host and capture output
  31. if {[catch {exec $hostCmd [lindex $arg 0]} output]} {
  32. putlog "Error executing $hostCmd: $output"
  33. return 0
  34. }
  35. # send every output line as a message
  36. foreach i [split $output "\n"] {
  37. puthelp "PRIVMSG $chan :$i"
  38. }
  39. return 1
  40. }
  41. namespace eval ::host {
  42. bind pub - !host ::host::lookup
  43. putlog "Loaded host.tcl"
  44. }