2ge has asked for the wisdom of the Perl Monks concerning the following question:

HI monks!

I have one question to you: what is the best way, how to check if server on some port is proxy, or socks server ? I wrote perl script for that, where I'm checking, if the port is open, if yes, I'm testing if it is proxy or socks. OK, but not that is my problem. I don't know how I can define timeout for socks5 connection, sometimes it connects around minute or more! I also tried add Timeout to Net\SOCKS.pm, but no luck. Do you think using alarm is good idea for that ? I'm not sure, so I'm asking you for your wisdom. I tried that on AS perl, and also on FreeBSD machine, so it is not windows related I guess. Thanks for any idea, how to fix that. Also I tried IO::Socket::Socks, it has the same behavior :(

use strict; use warnings; use URI; use IO::Socket; use Net::SOCKS; #my $server = '68.34.100.143:29992'; #works #my $server = '68.48.32.219:38884'; #opens, but no content my $server = '217.237.150.97:80'; #no timeout !?! my ($ip, $port) = ($1, $2) if $server =~ /([^:]+):(.*)/; my $page = URI->new('http://www.2ge.us/index.html'); my $fh = IO::Socket::INET-> new(PeerAddr => $ip, PeerPort => $port, Proto => 'tcp', Timeout => 5 ) || die "Can't open $server\n"; print "$server opened, trying socks5\n"; my $sock = new Net::SOCKS(socks_addr => $ip, socks_port => $port, user_id => '', user_password => '', force_nonanonymous => 0, protocol_version => 5) || die "Can't create socket\n"; my $conn = $sock->connect(peer_addr => inet_ntoa(inet_aton($page->host +())), peer_port => $page->port() ) || die "Can't connect to socks5 server\n"; #how to define timeout here ^^^ print "con. status:",Net::SOCKS::status_message($sock->param('status_n +um')),"\n"; $conn->autoflush(1); print "downloading...\n"; print $conn "GET " . $page->path() . " HTTP/1.1\n"; print $conn "Host: " . $page->host() . "\n"; print $conn "Connection: close\n\n"; while (<$conn>) { print } $sock->close(); __END__

2004-12-08 Janitored by Arunbear - added readmore tags, as per Monastery guidelines