odd you should say that. I use almost exactly the same code and I have never been troubled with lengthy delays. Are you sure you don't have a problem with DNS name resolution (even though your example shows the use of numeric IP addresses)?

Here is the code I use. It is part of a CGI script, so there is a $q CGI object hanging around, and a few constant values for pretty colors, such as use constant PAINT_OK => '#008000' and so on.

sub test_socket { my $s = IO::Socket::INET->new( @_, Timeout=>2, Proto => 'tcp' ); if( $s ) { close $s; $q->font( {-color=>PAINT_OK}, 'ok' ); } else { $q->font( {-color=>PAINT_NOK}, $! ) } } my %tcp_probe = ( 'foo<br>Apache' => test_socket( PeerHost => '172.17.0.2', Pe +erPort => 80, ), 'foo<br>Lotus' => test_socket( PeerHost => '172.17.0.2', Pe +erPort => 1352, ), 'bar<br>Apache' => test_socket( PeerHost => '172.17.0.3', Pe +erPort => 80, ), 'bar<br>Lotus' => test_socket( PeerHost => '172.17.0.3', Pe +erPort => 1352, ), 'example<br>Apache' => test_socket( PeerHost => 'www.example.com', + PeerPort => 80, ), 'example<br>Domino' => test_socket( PeerHost => 'www.example.com', + PeerPort => 8000, ), 'example<br>Lotus' => test_socket( PeerHost => 'www.example.com', + PeerPort => 1352, ), 'Web<br>Proxy' => test_socket( PeerHost => '172.17.0.9', + PeerPort => 8080, ), 'baz<br>Sybase' => test_socket( PeerHost => '172.17.0.1', Peer +Port => 4100, ), 'baz<br>Samba' => test_socket( PeerHost => '172.17.0.1', Peer +Port => 139, ), ); print $q->h3('Mission Critical'), $q->table( $q->TR( $q->th( {-width=>60, -valign=>'bottom', -bgcolor=>'#fff0e0'}, [ sort keys %tcp_probe ] ) ) . $q->TR( $q->td( {-width=>60, -align=>'center'}, [ map { $tcp_probe{$_} } sort keys %tcp_probe ] ) ) );

The only other thing I could suggest would be to set an alarm of a second or two, an alarm handler and eval the code, in order to forcibly cancel the code. But if it's blocking at a low enough level, alarm won't necessarily work either, I've had that happen in the past.


print@_{sort keys %_},$/if%_=split//,'= & *a?b:e\f/h^h!j+n,o@o;r$s-t%t#u'

In reply to Re: is there script to detect if remote machine is alive/reachable w/o using Net::Ping? by grinder
in thread is there script to detect if remote machine is alive/reachable w/o using Net::Ping? by Anonymous Monk

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.