line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
# $Id: HTTP.pm,v 1.3 2003/07/08 20:16:44 matt Exp $ |
2
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
package Net::SenderBase::Query::HTTP; |
4
|
1
|
|
|
1
|
|
632
|
use strict; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
37
|
|
5
|
1
|
|
|
1
|
|
6
|
use vars qw($HOST); |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
48
|
|
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
$HOST = 'www.senderbase.org'; |
8
|
|
|
|
|
|
|
|
9
|
1
|
|
|
1
|
|
5
|
use Socket qw(CRLF); |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
326
|
|
10
|
1
|
|
|
1
|
|
5
|
use IO::Socket; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
8
|
|
11
|
1
|
|
|
1
|
|
809
|
use Net::SenderBase; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
17
|
|
12
|
1
|
|
|
1
|
|
4
|
use Net::SenderBase::Results; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
400
|
|
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
sub new { |
15
|
0
|
|
|
0
|
0
|
|
my $class = shift; |
16
|
0
|
|
|
|
|
|
my %attrs = @_; |
17
|
|
|
|
|
|
|
|
18
|
0
|
0
|
|
|
|
|
$attrs{Address} || die "No address"; |
19
|
0
|
|
0
|
|
|
|
$attrs{Host} ||= $HOST; |
20
|
0
|
0
|
|
|
|
|
$attrs{Timeout} || die "No timeout"; |
21
|
|
|
|
|
|
|
|
22
|
0
|
|
|
|
|
|
my $self = bless { %attrs }, $class; |
23
|
|
|
|
|
|
|
|
24
|
0
|
|
|
|
|
|
return $self; |
25
|
|
|
|
|
|
|
} |
26
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
sub results { |
28
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
29
|
|
|
|
|
|
|
|
30
|
0
|
|
0
|
|
|
|
my $socket = IO::Socket::INET->new( |
31
|
|
|
|
|
|
|
PeerAddr => $self->{Host}, |
32
|
|
|
|
|
|
|
PeerPort => '80', |
33
|
|
|
|
|
|
|
Proto => 'tcp', |
34
|
|
|
|
|
|
|
Timeout => $self->{Timeout}, |
35
|
|
|
|
|
|
|
) || die "Connect to $self->{Host}:80 failed"; |
36
|
|
|
|
|
|
|
|
37
|
0
|
0
|
|
|
|
|
my $mask = $self->{Mask} ? "&mask=$self->{Mask}" : ''; |
38
|
0
|
|
|
|
|
|
print $socket "GET /check?ip=$self->{Address}$mask HTTP/1.0" , CRLF, |
39
|
|
|
|
|
|
|
"Host: $self->{Host}", CRLF, |
40
|
|
|
|
|
|
|
"User-Agent: Net::SenderBase/$Net::SenderBase::VERSION", |
41
|
|
|
|
|
|
|
CRLF, CRLF; |
42
|
|
|
|
|
|
|
|
43
|
0
|
|
|
|
|
|
local $/ = "\015\012"; |
44
|
|
|
|
|
|
|
|
45
|
0
|
|
|
|
|
|
my $proto = <$socket>; # HTTP/1.0 .... |
46
|
0
|
0
|
|
|
|
|
die "Invalid response" unless $proto =~ /^(HTTP\/\d+\.\d+)[ \t]+(\d+)[ \t]*([^\012]*)$/; |
47
|
0
|
|
|
|
|
|
my ($ver, $code, $msg) = ($1, $2, $3); |
48
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
HEADERS: |
50
|
0
|
|
|
|
|
|
while (<$socket>) { |
51
|
0
|
|
|
|
|
|
chomp; |
52
|
0
|
0
|
|
|
|
|
last HEADERS if /^$/m; |
53
|
|
|
|
|
|
|
} |
54
|
|
|
|
|
|
|
|
55
|
0
|
|
|
|
|
|
my $data = <$socket>; |
56
|
0
|
0
|
|
|
|
|
die "No results came back for $self->{Address}" unless $data; |
57
|
0
|
|
|
|
|
|
return Net::SenderBase::Results->cons($self->{Address}, $data); |
58
|
|
|
|
|
|
|
} |
59
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
1; |