4
0

host.tcl 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  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. #
  12. # See https://github.com/hwipl/eggdrop-scripts for the latest version and
  13. # additional information including the license (MIT).
  14. # tested versions, might run on earlier versions
  15. package require Tcl 8.6
  16. package require eggdrop 1.8.4
  17. namespace eval ::host {
  18. # channel flag for enabling/disabling
  19. setudef flag host
  20. # path to host tool
  21. variable hostCmd "/usr/bin/host"
  22. }
  23. proc ::host::lookup { nick host hand chan arg } {
  24. variable hostCmd
  25. # check channel flag if enabled in this channel
  26. if {![channel get $chan host]} {
  27. return 0
  28. }
  29. # check if hostname/ip parameter is given
  30. if {$arg == ""} {
  31. return 0
  32. }
  33. # run host and capture output
  34. if {[catch {exec $hostCmd [lindex $arg 0]} output]} {
  35. putlog "Error executing $hostCmd: $output"
  36. return 0
  37. }
  38. # send every output line as a message
  39. foreach i [split $output "\n"] {
  40. puthelp "PRIVMSG $chan :$i"
  41. }
  42. return 1
  43. }
  44. namespace eval ::host {
  45. bind pub - !host ::host::lookup
  46. putlog "Loaded host.tcl"
  47. }