OK This is what I am trying to do:
Whenever I say "<botnick> scan <host> <port>" the bot is supposed to open a tcp socket to <host> <port>.
However, I need to check if the socket has opened (ie if the port is open on that host )..
This is my script:
proc scan_test { nick uhost handle channel text } {
set host [lindex "$text" 0]; set port [lindex "$text" 1]; set z [socket -async $host $port];
putquick "privmsg $channel :Scanning $host on $port.."
if {[fconfigure $z -error] == "connection refused"} {
puthelp "privmsg $channel :Port Closed: $port";
} elseif {[fconfigure $z -error] == ""} {
puthelp "privmsg $channel :Port Open: $port"
}
close $z
}
bind pub - scan scan_test
Now.. On to the problem.. Even if a port is closed, fconfigure $z -error ALWAYS evaluates to "" (which should be the outcome of a SUCCESSFUL connection) Any ideas on what I can do?
if {[catch {socket $a $p} e]} {
# $e is the error message
} {
# connected...$e is the socket id
# ...so close it and tell the user the port is open
close $e
}
Hi, about the async sockets... you can't check for the error until the socket has had some time to try to connect. Use 'fileevent writable' and 'fileevent readable' to set up a callback. Technically you should only have to use the 'writable' event, but the tcl docs are a bit unclear. Anyway, once the async socket is marked readable/writable, that means that it's either connected or in an error state.<br>
<br>
Also, you may want to use eggdrop's dns commands instead of calling 'socket' right away, because eggdrop's are nonblocking. Not an issue if you always use ip addresses of course.