line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package WWW::DomainTools::SearchEngine; |
2
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
BEGIN { |
4
|
2
|
|
|
2
|
|
42968
|
use Exporter (); |
|
2
|
|
|
|
|
6
|
|
|
2
|
|
|
|
|
75
|
|
5
|
2
|
|
|
2
|
|
13
|
use vars qw ($VERSION @ISA @EXPORT @EXPORT_OK %EXPORT_TAGS); |
|
2
|
|
|
|
|
5
|
|
|
2
|
|
|
|
|
282
|
|
6
|
2
|
|
|
2
|
|
11
|
$VERSION = "0.06"; |
7
|
2
|
|
|
|
|
41
|
@ISA = qw (Exporter); |
8
|
2
|
|
|
|
|
5
|
@EXPORT = qw (); |
9
|
2
|
|
|
|
|
4
|
@EXPORT_OK = qw (); |
10
|
2
|
|
|
|
|
42
|
%EXPORT_TAGS = (); |
11
|
|
|
|
|
|
|
} |
12
|
|
|
|
|
|
|
|
13
|
2
|
|
|
2
|
|
13
|
use base qw( WWW::DomainTools ); |
|
2
|
|
|
|
|
18
|
|
|
2
|
|
|
|
|
742
|
|
14
|
|
|
|
|
|
|
use List::Util qw/ first /; |
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
=head1 NAME |
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
WWW::DomainTools::SearchEngine - Search domain names for availability |
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
=head1 SYNOPSIS |
22
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
use WWW::DomainTools::SearchEngine; |
24
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
my $api = WWW::DomainTools::SearchEngine->new( |
26
|
|
|
|
|
|
|
key => '12345', |
27
|
|
|
|
|
|
|
partner => 'yourname', |
28
|
|
|
|
|
|
|
customer_ip => '1.2.3.4' |
29
|
|
|
|
|
|
|
); |
30
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
my $res = $api->request( |
32
|
|
|
|
|
|
|
ext => "COM|NET|ORG|INFO", |
33
|
|
|
|
|
|
|
q => 'example.com', |
34
|
|
|
|
|
|
|
); |
35
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
=head1 DESCRIPTION |
37
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
This module allows you to use the Domain Tools domain search XML API. You will |
39
|
|
|
|
|
|
|
need to get a license key. |
40
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
L |
42
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
=head1 METHODS |
44
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
=over 4 |
46
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
=item request( url parameters hash ) |
48
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
The keys and values expected are documented on the Domain Tools website. |
50
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
If the request is successful, the return value is either a hash reference or |
52
|
|
|
|
|
|
|
a string depending on the value of the 'format' parameter to the constructor. |
53
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
See the documentation for the new() method for more detailed information |
55
|
|
|
|
|
|
|
about 'format' and other standard parameters. |
56
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
If the HTTP request fails, this method will die. |
58
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
=back |
60
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
=over 4 |
62
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
=item domain_is_available( domain_name ) |
64
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
Pass in a domain name. It will return either a 1 or a 0 indicating that the domain |
66
|
|
|
|
|
|
|
name is available for registration (or not). |
67
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
TLS's that are currently checked for availability are .com .net .org .info .biz .us |
69
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
If you attempt to check availability of a domain name with an unsupported TLD, this |
71
|
|
|
|
|
|
|
method will die(). |
72
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
If the HTTP request fails, this method will die. |
74
|
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
=back |
76
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
=over 4 |
78
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
=item new( options hash ) |
80
|
|
|
|
|
|
|
|
81
|
|
|
|
|
|
|
Valid keys are: |
82
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
=over 4 |
84
|
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
=item * url |
86
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
Your XML api full url. Eg. http://partnername.whoisapi.com/api.xml |
88
|
|
|
|
|
|
|
|
89
|
|
|
|
|
|
|
The default is http://engine.whoisapi.com/api.xml |
90
|
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
=item * key |
92
|
|
|
|
|
|
|
|
93
|
|
|
|
|
|
|
Your license key |
94
|
|
|
|
|
|
|
|
95
|
|
|
|
|
|
|
=item * partner |
96
|
|
|
|
|
|
|
|
97
|
|
|
|
|
|
|
Your partner ID |
98
|
|
|
|
|
|
|
|
99
|
|
|
|
|
|
|
=item * customer_ip |
100
|
|
|
|
|
|
|
|
101
|
|
|
|
|
|
|
The (optional) IP of the customer that you are making the request for |
102
|
|
|
|
|
|
|
|
103
|
|
|
|
|
|
|
=item * format |
104
|
|
|
|
|
|
|
|
105
|
|
|
|
|
|
|
How you want the response returned when you call the request method. |
106
|
|
|
|
|
|
|
|
107
|
|
|
|
|
|
|
'hash' is the default and means that you want a hash reference returned which |
108
|
|
|
|
|
|
|
is built by using L. |
109
|
|
|
|
|
|
|
|
110
|
|
|
|
|
|
|
'xml' means that you want a string returned containing the raw XML response. |
111
|
|
|
|
|
|
|
|
112
|
|
|
|
|
|
|
=item * timeout |
113
|
|
|
|
|
|
|
|
114
|
|
|
|
|
|
|
The number of seconds that you want to wait before cancelling the HTTP request. |
115
|
|
|
|
|
|
|
|
116
|
|
|
|
|
|
|
default: 10 |
117
|
|
|
|
|
|
|
|
118
|
|
|
|
|
|
|
=item * lwp_ua |
119
|
|
|
|
|
|
|
|
120
|
|
|
|
|
|
|
An instance of L to use for the requests. This will allow you |
121
|
|
|
|
|
|
|
to set up an L with all of the settings that you would like to |
122
|
|
|
|
|
|
|
use such as proxy settings etc. |
123
|
|
|
|
|
|
|
|
124
|
|
|
|
|
|
|
default: LWP::UserAgent->new |
125
|
|
|
|
|
|
|
|
126
|
|
|
|
|
|
|
=back |
127
|
|
|
|
|
|
|
|
128
|
|
|
|
|
|
|
=back |
129
|
|
|
|
|
|
|
|
130
|
|
|
|
|
|
|
=head1 SEE ALSO |
131
|
|
|
|
|
|
|
|
132
|
|
|
|
|
|
|
L |
133
|
|
|
|
|
|
|
L |
134
|
|
|
|
|
|
|
L |
135
|
|
|
|
|
|
|
|
136
|
|
|
|
|
|
|
=head1 BUGS |
137
|
|
|
|
|
|
|
|
138
|
|
|
|
|
|
|
Please report bugs using the CPAN Request Tracker at L |
139
|
|
|
|
|
|
|
|
140
|
|
|
|
|
|
|
=head1 AUTHOR |
141
|
|
|
|
|
|
|
|
142
|
|
|
|
|
|
|
David Bartle |
143
|
|
|
|
|
|
|
|
144
|
|
|
|
|
|
|
=head1 COPYRIGHT |
145
|
|
|
|
|
|
|
|
146
|
|
|
|
|
|
|
This program is free software; you can redistribute |
147
|
|
|
|
|
|
|
it and/or modify it under the same terms as Perl itself. |
148
|
|
|
|
|
|
|
|
149
|
|
|
|
|
|
|
I am not affiliated with Domain Tools or Name Intelligence. The use of |
150
|
|
|
|
|
|
|
their API's are governed by their own terms of service: |
151
|
|
|
|
|
|
|
|
152
|
|
|
|
|
|
|
http://www.domaintools.com/members/tos.html |
153
|
|
|
|
|
|
|
|
154
|
|
|
|
|
|
|
The full text of the license can be found in the |
155
|
|
|
|
|
|
|
LICENSE file included with this module. |
156
|
|
|
|
|
|
|
|
157
|
|
|
|
|
|
|
=cut |
158
|
|
|
|
|
|
|
|
159
|
|
|
|
|
|
|
sub _init { |
160
|
|
|
|
|
|
|
my ($self) = @_; |
161
|
|
|
|
|
|
|
|
162
|
|
|
|
|
|
|
%{ $self->{default_params} } = ( |
163
|
|
|
|
|
|
|
appname => 'search_engine', |
164
|
|
|
|
|
|
|
version => 4 |
165
|
|
|
|
|
|
|
); |
166
|
|
|
|
|
|
|
|
167
|
|
|
|
|
|
|
} |
168
|
|
|
|
|
|
|
|
169
|
|
|
|
|
|
|
sub domain_is_available { |
170
|
|
|
|
|
|
|
my ( $self, $domain_name ) = @_; |
171
|
|
|
|
|
|
|
|
172
|
|
|
|
|
|
|
my $top_level_domain = ( reverse split( /\./, $domain_name ) )[0]; |
173
|
|
|
|
|
|
|
|
174
|
|
|
|
|
|
|
## make sure this tld is supported by the API |
175
|
|
|
|
|
|
|
if ( !first { lc($_) eq lc($top_level_domain) } |
176
|
|
|
|
|
|
|
@WWW::DomainTools::VALID_TLDS ) |
177
|
|
|
|
|
|
|
{ |
178
|
|
|
|
|
|
|
die("The TLD $top_level_domain is not supported by this API"); |
179
|
|
|
|
|
|
|
} |
180
|
|
|
|
|
|
|
|
181
|
|
|
|
|
|
|
## perform the domain tools search |
182
|
|
|
|
|
|
|
my $result = $self->request( |
183
|
|
|
|
|
|
|
ext => |
184
|
|
|
|
|
|
|
$self->_tld_list_to_ext_param(@WWW::DomainTools::VALID_TLDS), |
185
|
|
|
|
|
|
|
q => $domain_name, |
186
|
|
|
|
|
|
|
exactfirst => 'y', |
187
|
|
|
|
|
|
|
); |
188
|
|
|
|
|
|
|
|
189
|
|
|
|
|
|
|
## if no records were returned, this means that it's available |
190
|
|
|
|
|
|
|
|
191
|
|
|
|
|
|
|
if ( $result->{response}->{records_returned} == 0 ) { |
192
|
|
|
|
|
|
|
return 1; |
193
|
|
|
|
|
|
|
} |
194
|
|
|
|
|
|
|
|
195
|
|
|
|
|
|
|
my $status_line = $result->{response}->{e}->{e_s}; |
196
|
|
|
|
|
|
|
my $extn_line = $result->{response}->{extn}; |
197
|
|
|
|
|
|
|
my $tld_status_lookup |
198
|
|
|
|
|
|
|
= $self->_res_status_lookup( $status_line, $extn_line ); |
199
|
|
|
|
|
|
|
my $tld_status = $tld_status_lookup->{$top_level_domain}; |
200
|
|
|
|
|
|
|
|
201
|
|
|
|
|
|
|
## take the exact match and look at the availability for the requested tld |
202
|
|
|
|
|
|
|
if ( $tld_status eq "q" || $tld_status eq "d" ) { |
203
|
|
|
|
|
|
|
return 1; |
204
|
|
|
|
|
|
|
} |
205
|
|
|
|
|
|
|
|
206
|
|
|
|
|
|
|
return 0; |
207
|
|
|
|
|
|
|
|
208
|
|
|
|
|
|
|
} |
209
|
|
|
|
|
|
|
|
210
|
|
|
|
|
|
|
1; |