This is the new home of the egghelp.org community forum.
All data has been migrated (including user logins/passwords) to a new phpBB version.


For more information, see this announcement post. Click the X in the top right-corner of this box to dismiss this message.

[request] a Socket check script

Old posts that have not been replied to for several years.
Locked
D
Darkstar

[request] a Socket check script

Post by Darkstar »

hello.

I am a noob in tcl and never scripted any tcl scripts before but I also have no time to learn TCL since I follow college and work on my website alott.
I am looking for a tcl script that will check if a server+port is online.
Currently I have a website version of it with using the php fsockopen commando, look here: http://hbr.relaxz.net/?page=status
And i was wondering how to make it a tcl eggdrop addon so people can use a commando like !online [number or server name] to see if it is online or now.

Thanks.
User avatar
stdragon
Owner
Posts: 959
Joined: Sun Sep 23, 2001 8:00 pm
Contact:

Post by stdragon »

I didn't test this, just sort of wrote it down, but maybe it will work for you. You call it like

test_host_port yahoo.com 82 my_callback

and you define a proc called my_callback like:

proc my_callback {host port err} {
if {$err == ""} { putlog "$host : $port is open" } else { putlog "couldn't connect to $host : $port - $err" }
}

anyway, here's the code:

Code: Select all

proc test_host_port {host port callback} {
  # first resolve the host to an ip (async)
  dnslookup $host [list host_resolved $callback $port]
}

proc host_resolved {callback port ip host success} {
  # see if we have a valid ip
  if {![string compare $ip "0.0.0.0"]} {
    eval $callback [list $host $port 0]
    return 1
  }
  # now open an async socket
  set sock [socket -async $ip $port]
  fileevent $sock writable [list sock_result $callback $host $port $sock]
}

proc sock_result {callback host port sock} {
  set err [fconfigure $sock -error]
  close $sock
  eval $callback [list $host $port $err]
}
D
Darkstar

Post by Darkstar »

thank you.
D
Darkstar

Post by Darkstar »

I dont really understand :/
As i said I am a tcl noob.
Locked