#!/usr/bin/perl use strict; use warnings; use IO::Socket; use IO::Select; my @ports = qw/65051 65071 65052 65072 65081 65088 65082 65039/; my @hosts = ( "example.com", "google.com", ); my $readers = IO::Select->new(); foreach my $host (@hosts) { foreach my $port (@ports) { print "* Trying: $host\n"; my $socket = IO::Socket::INET->new( PeerAddr => $host, PeerPort => "http(80)", LocalPort => $port, Proto => 'tcp', ReuseAddr => 1, Blocking => 0, ) or die "Couldn't connect to server: $!"; $readers->add($socket); print $socket "GET / HTTP/1.0\r\n\r\n"; $socket = undef; } print "\n"; } while (1) { foreach my $sock (my @ready_for_read = $readers->can_read()) { my @recv_lines = <$sock>; print join "\n", map { s/\r?\n//; $_ } @recv_lines; print "\n"; $readers->remove($sock); $sock->close; } }