That doesn't seems to work:
#!/usr/bin/perl
use strict;
use warnings;
use AnyEvent;
use AnyEvent::HTTP;
use AnyEvent::Socket qw( tcp_connect );
use Socket;
open my $fh, "<", "host_list.txt";
my @hosts = <$fh>;
close $fh;
chomp @hosts;
my @ports = qw/65011 65021 65012 65022 65031 65038 65032 65039/;
my $cv = AnyEvent->condvar;
foreach my $port (@ports) {
foreach my $host (@hosts) {
print "[*] $host:$port\n";
$cv->begin;
check_http($port, $host);
}
}
$cv->recv;
sub check_http {
my ($port_number, $host) = @_;
my $ret_val;
$host = 'http://' . $host;
http_get $host,
persistent => 0,
on_prepare => sub {
my ($fh) = @_;
bind($fh, sockaddr_in($port_number, INADDR_ANY))
or print "bind: $!\n";
15
},
sub {
my ($body, $hdr) = @_;
if ($hdr->{Status} =~ /^2/) {
print "Seems OK! (:\n";
} else {
print "ERROR, $hdr->{Status} $hdr->{Reason}\n";
}
print "[X] $host:$port_number\n";
$cv->end;
};
}
-
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.
|