# Set flag required for checking the status of a port. # set portchk_setting(flag) "" # Set the pub command for checking the status of a port here. # set portchk_setting(cmd_pub) "`port" # Show all data from a connection? # set portchk_setting(read) 1 #################### # Code begins here # #################### if {![string match 1.6.* $version]} { putlog "\002portchk:\002 \002CRITICAL ERROR\002 portchk.tcl requires eggdrop 1.6.x to run." die "\002portchk:\002 \002CRITICAL ERROR\002 portchk.tcl requires eggdrop 1.6.x to run." } bind pub $portchk_setting(flag) $portchk_setting(cmd_pub) portchk_scan_pub setudef flag portchk proc portchk_dopre {} { global portchk_setting if {!$portchk_setting(portchk:)} { return "" } elseif {!$portchk_setting(bold)} { return "portchk: " } else { return "\002portchk:\002 " } } proc portchk_scan_pub {nick uhost hand chan text} { global portchk_setting set host [lindex [split $text] 0] set port [lindex [split $text] 1] if {$port == ""} { putquick "NOTICE $nick :Usage: $portchk_setting(cmd_pub) " } else { if {[catch {set sock [socket -async $host $port]} error]} { putquick "PRIVMSG $chan :\[4Port Check\] 7Connection to $host 7port $port 4Refused" } else { set timerid [utimer 15 [list portchk_timeout_pub $chan $sock $host $port]] fileevent $sock writable [list portchk_connected_pub $chan $sock $host $port $timerid] } } } proc portchk_connected {idx sock host port timerid} { killutimer $timerid set error [fconfigure $sock -error] if {$error != ""} { close $sock putdcc $idx "[portchk_dopre]7Connection to $host 7port $port 4Failed \(4[string totitle $error]\)" } else { fileevent $sock writable {} fileevent $sock readable [list portchk_read $idx $sock $host $port] putdcc $idx "[portchk_dopre]7Connection to $host 7port $port 3Accepted" } } proc portchk_timeout {idx sock host port} { close $sock putdcc $idx "[portchk_dopre]7Connection to $host 7port $port 4Timed Out" } proc portchk_read {idx sock host port} { global portchk_setting if {$portchk_setting(read)} { if {[gets $sock read] == -1} { putdcc $idx "[portchk_dopre]7EOF On Connection To $host 7port $port 4Socket Closed." close $sock } else { putdcc $idx "[portchk_dopre]$host \($port\) > $read" } } else { close $sock } } proc portchk_connected_pub {chan sock host port timerid} { killutimer $timerid set error [fconfigure $sock -error] if {$error != ""} { close $sock putquick "PRIVMSG $chan :\[4Port Check\] 7Connection to $host 7port $port 4Failed \(4[string totitle $error]\)" } else { fileevent $sock writable {} fileevent $sock readable [list portchk_read_pub $chan $sock $host $port] putquick "PRIVMSG $chan :\[4Port Check\] 7Connection to $host 7port $port 3Accepted" } } proc portchk_timeout_pub {chan sock host port} { close $sock putquick "PRIVMSG $chan :\[4Port Check\] 7Connection to $host 7port $port 4Timed Out" } proc portchk_read_pub {sock} { global portchk_setting if {!$portchk_setting(read)} { close $sock } elseif {[gets $sock read] == -1} { putquick "PRIVMSG $chan :7EOF On Connection To $host 7port $port 4Socket Closed." close $sock } } proc portchk_unsvrban {chan host} { putserv "MODE $chan -b *!*@$host" } putlog "=== EchiEgg Port Check TCL Loaded"