I am writing a program that scans through a list of servers that i have and connects to them all one by one to make sure that they are valid servers, however if i happen to pass over a telnet server, my program hangs up during the handshaking process. Normally, i would go ahead and have the program complete the whole handshaking process but since it's uneccessary for this particular program i'd rather not do that if possible, i've tried different ways of making the connection timeout all to no avail, here's some of the code i'm using to make the connection. Any ideas would be very much appreciated.
shortened for brevity:
-------------------------------------------------
&connect_host;
send(SOCKET,$begin, 0);
while (defined($_ = <SOCKET>)) {
if ($_ =~ /3point\>/ig){
$valid = 1;
close SOCKET;
} else {
$valid = 0;
close SOCKET;
}
}
if ($valid == 1){
print "valid server\n";
} else {
print "invalid server\n";
}
sub connect_host{
$iaddr = inet_aton($host) or die "ERROR1: $!\n";
$port = sockaddr_in($port, $iaddr) or die "ERROR2: $!\n";
$proto = getprotobyname('tcp') or die "ERROR3: $!\n";
socket(SOCKET, PF_INET, SOCK_STREAM, $proto) or die "ERROR4: $!\n";
connect(SOCKET, $port) or die "ERROR5: $!\n";
}
---------
:|
Edit: chipmunk 2001-05-17