summaryrefslogtreecommitdiffstats
path: root/cmd_resolve.tcl
blob: 36ccb4eafbcc96ea64f6d86664a9fbb25f1ea7a0 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
#
# cmd_resolve.tcl
#  written by Jeff Fisher (guppy@eggheads.org)
#
# This script adds the commands '.resolve' and '.dns' which can be used to
# lookup hostnames or ip addresses in the partyline without causing the bot
# to block while doing so thanks to the dns module.
#
# updates
# -------
#  15Apr2003: fixed a logging bug and stop using regexp incorrectly
#  05Nov2000: fixed a nasty security hole, .resolve [die] <grin>
#  04Nov2000: first version
#
# $Id: cmd_resolve.tcl,v 1.4 2003/04/16 01:03:04 guppy Exp $

bind dcc -|- resolve resolve_cmd
bind dcc -|- dns resolve_cmd

proc resolve_cmd {hand idx arg} {
  global lastbind
  if {[scan $arg "%s" hostip] != 1} {
    putidx $idx "Usage: $lastbind <host or ip>"
  } else {
    putidx $idx "Looking up $hostip ..."
    set hostip [split $hostip]
    dnslookup $hostip resolve_callback $idx $hostip $lastbind
  }
  return 0
}

proc resolve_callback {ip host status idx hostip cmd} {
  if {![valididx $idx]} {
    return 0
  } elseif {!$status} {
    putidx $idx "Unable to resolve $hostip"
  } elseif {[string tolower $ip] == [string tolower $hostip]} {
    putidx $idx "Resolved $ip to $host"
  } else {
    putidx $idx "Resolved $host to $ip"
  }
  putcmdlog "#[idx2hand $idx]# $cmd $hostip"
  return 0
}

loadhelp cmd_resolve.help

putlog "Loaded cmd_resolve.tcl successfully."