coolguylentz

nslookup.tcl eggdrop script

Feb 25th, 2013
415
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
TCL 5.61 KB | None | 0 0
  1. #### nslookup.tcl v1.0.1 #######################################################
  2. ################################################################################
  3. ## Written by:                                                                ##
  4. ##   KuNgFo0  (http://www.eggfaq.com/).                                       ##
  5. ##                                                                            ##
  6. ## Modified by:                                                               ##
  7. ##   Brian Schmidt aka. brianMan.                                             ##
  8. ################################################################################
  9.  
  10. #### Readme / Help #############################################################
  11. ################################################################################
  12. ## This is a slightly modified version of KuNgFoO's nslookup.tcl v0.5 script. ##
  13. ##                                                                            ##
  14. ## Script that can do nslookups.                                              ##
  15. ##                                                                            ##
  16. ## Usage:                                                                     ##
  17. ##   To have the .dns command available on a channel you need to set the      ##
  18. ##   channel flag +nslookups from the console/partyline .                     ##
  19. ##   ``.chanset #channel +nslookupsŽŽ                                         ##
  20. ##                                                                            ##
  21. ## Channel Commands (available only if channel is +nslookups):                ##
  22. ##   .dns [ host|ip|nick[ host|ip|nick][ ...]]                                ##
  23. ## Example:                                                                   ##
  24. ##   ``.dns www.eggfaq.comŽŽ                                                  ##
  25. ################################################################################
  26.  
  27. #### Changelog #################################################################
  28. ################################################################################
  29. ## v1.0.1                                                                     ##
  30. ## * Minor code cleanup                                                       ##
  31. ##                                                                            ##
  32. ## v1.0.0                                                                     ##
  33. ## + Initial release.                                                         ##
  34. ## + Added the possibility to control which channels could use the commands   ##
  35. ##   with the channel flag ``+/-nslookupŽŽ                                    ##
  36. ################################################################################
  37.  
  38. # Set then next line as the command you want to initate the nslookup
  39. set nslookup_command ".dns"
  40.  
  41. # Set the flagname used for enabling the channel command
  42. set nslookup_channel_flag "nslookup"
  43.  
  44. # Set the next line as the flag required to use the command
  45. set nslookup_flag "-"
  46.  
  47. # Set the next line as the exec command to run
  48. # (Only if you're running an older eggdrop or not using the nslookup module)
  49. set nslookup_exec "nslookup -silent"
  50.  
  51. bind pub $nslookup_flag|$nslookup_flag $nslookup_command pub_nslookup
  52.  
  53. proc pub_nslookup {nick uhost hand chan arg} {
  54.     global nslookup_command nslookup_exec botnick nslookup_channel_flag
  55.     if {([channel get $chan $nslookup_channel_flag]) && (![matchattr $hand b]) && ($nick != $botnick)} {
  56.         if {$arg == ""} {
  57.             putserv "PRIVMSG $chan :Usage: $nslookup_command  \[host/ip/nick #2\] ..."
  58.         } else {
  59.             foreach addr [set addrs [split $arg {,;| }]] {
  60.                 if {$addr == ""} {
  61.                     continue ; # ignore
  62.                 }
  63.                 if {[set tmp [getchanhost $addr]] != ""} {
  64.                     set addr [lindex [split $tmp @] end]
  65.                 }
  66.                 if {![regexp {^[a-zA-Z0-9\.\-]*$} $addr]} {
  67.                     putserv "PRIVMSG $chan :Error: Hostname '$addr' contains illegal characters" ; # vulnerability
  68.                 } elseif {[string index $addr 0] == "-"} {
  69.                     putserv "PRIVMSG $chan :Error: Hostnames cannot begin with a - character ($addr)" ; # vulnerability
  70.                 } elseif {[info commands dnslookup] != ""} {
  71.                     dnslookup $addr return_nslookup $chan $addr
  72.                 } elseif {[catch {exec bash -c "$nslookup_exec '$addr'"} output]} {
  73.                     putserv "PRIVMSG $chan :Could not resolve $addr"
  74.                 } else {
  75.                     foreach line [split $output \n] {
  76.                         if {[lindex $line 0] == "Name:"} {
  77.                             set host [lrange $line 1 end]
  78.                         } elseif {([lindex $line 0] == "Address:") || ([lindex $line 0] == "Addresses:")} {
  79.                             set ip [lrange $line 1 end]
  80.                         }
  81.                     }
  82.                     if {([info exists host]) && ([info exists ip])} {
  83.                         return_nslookup $ip $host 1 $chan $addr
  84.                     } else {
  85.                         return_nslookup "" "" 0 $chan $addr
  86.                     }
  87.                 }
  88.             }
  89.         }
  90.     }
  91. }
  92.  
  93. proc return_nslookup {ip host status chan addr} {
  94.     if {$status} {
  95.         if {[string match *$ip* $addr]} {
  96.             putserv "PRIVMSG $chan :$ip -> $host"
  97.         } else {
  98.             putserv "PRIVMSG $chan :$host -> $ip"
  99.         }
  100.     } else {
  101.         putserv "PRIVMSG $chan :Could not resolve $addr"
  102.     }
  103. }
  104.  
  105. setudef flag $nslookup_channel_flag
  106. putlog "*** LOADED: nslookup.tcl"
Advertisement
Add Comment
Please, Sign In to add comment