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
-
Are you posting in the right place? Check out Where do I post X? to know for sure.
-
Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
<code> <a> <b> <big>
<blockquote> <br /> <dd>
<dl> <dt> <em> <font>
<h1> <h2> <h3> <h4>
<h5> <h6> <hr /> <i>
<li> <nbsp> <ol> <p>
<small> <strike> <strong>
<sub> <sup> <table>
<td> <th> <tr> <tt>
<u> <ul>
-
Snippets of code should be wrapped in
<code> tags not
<pre> tags. In fact, <pre>
tags should generally be avoided. If they must
be used, extreme care should be
taken to ensure that their contents do not
have long lines (<70 chars), in order to prevent
horizontal scrolling (and possible janitor
intervention).
-
Want more info? How to link
or How to display code and escape characters
are good places to start.
|