"Probe"

Summary

This small program tries connect() to a TCP port of a destination node with timeout.

As you may have noticed, when the destination host you are trying to reach is unreacheable for various network reasons, connect() won't return for a while. (The default connect() does not allow us to specify timeout value.) So if you want to run your script on a PlanetLab node using ssh, your script hangs indefinitely when the node is unreacheable.
For example, as of 11/21/2003, the following PlanetLab nodes are unreacheable from Princeton and you will probably experience a very long timeout before getting back from unsuccessful ssh to them. I had worked on connect() with timeout for my event-driven underlay programs, so they do not suffer from a long timeout in connect(). The idea is to use non-blocking socket with connect, but it took me a while to figure out how to do this. (I can show you the source code if you are interested.) However, this modified connect() does not solve the problem of ssh above, unless we recompile ssh with this new connect(). A workaround to this is to run a small program called "probe" to try connecting to TCP port 22 with this modified connect(). In your script, before doing ssh, you can first "probe" TCP port 22 of the destination with some timeout value, and then only when it succeeds, you can proceed to do ssh; otherwise you do not ssh.

Usage

Here is the usage of probe command.
usage: probe <ip_addr> <port> [timeout(sec); default 5sec]

Exit Code

On success, it exits with 0; otherwise with -1;

Example

Example of using "probe" in perl is as follows.
. . . # after forking this child process ... # # probe with timeout # $do_not_ssh = 0; $proba_path="./probe"; $probe_cmd="$probe_path $host 22 3"; # probe ssh port with 3 sec timeout $probe_out =execute($probe_cmd); if ($probe_out =~ /Connection timed out/) { print STDERR "connection to $host timed out"; $do_not_ssh = 1; } elsif ($probe_out =~ /Permission denied/) { print STDERR "connection to $host timed out"; $do_not_ssh = 1; } elsif ($probe_out =~ /Connection refused/) { print STDERR "connection to $host refused"; $do_not_ssh = 1; } if ($do_not_ssh==0) { # # run script using ssh # } sub execute { my $tie=" 2>&1"; # combining stdout and stderr my $cmd = $_[0]; return `$cmd $tie`; }

Download

"Probe" can be downloaded from here (binary only for now). It should run on (PlanetLab) Linux machines. Bug report should be directed to me. (Aki).

Notes


Author:Akihiro Nakao