File Coverage

blib/lib/Net/Domain/Registration/Check.pm
Criterion Covered Total %
statement 23 42 54.7
branch 0 10 0.0
condition 0 3 0.0
subroutine 8 9 88.8
pod 0 1 0.0
total 31 65 47.6


line stmt bran cond sub pod time code
1             package Net::Domain::Registration::Check;
2              
3 1     1   13033 use 5.006;
  1         4  
4 1     1   6 use strict;
  1         1  
  1         16  
5 1     1   3 use warnings;
  1         8  
  1         24  
6 1     1   430 use utf8;
  1         12  
  1         5  
7 1     1   25 use Carp;
  1         1  
  1         51  
8 1     1   394 use Net::DNS;
  1         65739  
  1         85  
9 1     1   579 use Net::Domain::TLD qw(tld_exists);
  1         8210  
  1         107  
10 1     1   8 use base qw(Exporter);
  1         2  
  1         262  
11              
12             our @EXPORT = qw(domain_on_parent);
13              
14              
15              
16             =head1 NAME
17              
18             Net::Domain::Registration::Check - Fast check on availability of domain registration
19              
20             =head1 VERSION
21              
22             Version 0.01
23              
24             =cut
25              
26             our $VERSION = '0.01';
27              
28              
29             =head1 SYNOPSIS
30              
31             This module takes a quick check on domain registration, if the domain is available or not.
32              
33             It doesn't query to whois server, just checks if domain exists on its parent nameservers.
34              
35             So it gets a quick check.
36              
37             For domain which is redemptionPeriod status, it does not get listed on parent nameservers, but you can't register it from the registrar this time. See: https://icann.org/epp#redemptionPeriod
38              
39             It doesn't make sense on second-level ccTLDs, such as com.cn, co.uk etc. For IANA official root zone DB please see: https://www.iana.org/domains/root/db
40              
41             该模块用来快速检查域名是否可以被注册。
42              
43             它并不查询whois服务器,而是检查该域名是否存在于父一级的名字服务器上。
44              
45             所以它的查询非常迅速,远快于whois.
46              
47             某些待删除的域名处于redemptionPeriod状态,它确实不存在于父一级名字服务器上,但是这个时候你还不能注册。请见:https://icann.org/epp#redemptionPeriod
48              
49             请注意:该模块并不能查询到ccTLD里,各国自己设置的二级域名,比如com.cn,co.uk。IANA官方定义的顶级域名gTLD和国家级域名ccTLD请见:https://www.iana.org/domains/root/db
50              
51              
52             use Net::Domain::Registration::Check;
53            
54             print domain_on_parent($domain) ? "domain has been taken" : "domain may not be taken";
55              
56              
57              
58             =head1 EXPORT
59              
60             This module exports only one method, domain_on_parent(), to check if domain exists on its parent nameservers.
61              
62             该模块输出唯一的方法,domain_on_parent(),用来检查域名是否存在于父一级名字服务器上。
63              
64              
65             =cut
66              
67             sub domain_on_parent {
68              
69 0   0 0 0   my $domain = shift || croak "no domain provided";
70 0           my $tld;
71              
72 0 0         if ($domain =~ /^(.*?)\.(.*)$/) {
73 0           $tld = $2;
74             }
75            
76 0 0         croak "domain TLD not exists" unless tld_exists($tld);
77              
78 0           my $res = Net::DNS::Resolver->new;
79 0           my $answer = $res->query($tld, 'NS');
80 0           my @nameservers;
81              
82 0 0         if (defined $answer) {
83 0           my @rr= $answer->answer;
84 0           for (@rr) {
85 0           my $ns = $_->rdatastr;
86 0           push @nameservers, $ns;
87             }
88             }
89              
90 0           $res = Net::DNS::Resolver->new(nameservers => [@nameservers]);
91 0           $answer = $res->send($domain);
92              
93 0 0         if ( $answer->header->rcode eq 'NXDOMAIN' ) {
    0          
94 0           return 0;
95             } elsif ( $answer->header->rcode eq 'NOERROR') {
96 0           return 1;
97             } else {
98 0           croak "unsure on domain status: $answer->header->rcode";
99             }
100             }
101              
102              
103             =head1 AUTHOR
104              
105             Peng Yonghua
106              
107             =head1 BUGS
108              
109             Please report any bugs or feature requests to , I will respond it quickly.
110              
111              
112              
113              
114             =head1 SUPPORT
115              
116             You can find documentation for this module with the perldoc command.
117              
118             perldoc Net::Domain::Registration::Check
119              
120              
121             You can also look for information at:
122              
123             =over 4
124              
125             =item * RT: CPAN's request tracker (report bugs here)
126              
127             L
128              
129             =item * AnnoCPAN: Annotated CPAN documentation
130              
131             L
132              
133             =item * CPAN Ratings
134              
135             L
136              
137             =item * Search CPAN
138              
139             L
140              
141             =back
142              
143              
144             =head1 ACKNOWLEDGEMENTS
145              
146              
147             =head1 LICENSE AND COPYRIGHT
148              
149             Copyright 2017 Peng Yonghua.
150              
151             This program is free software; you can redistribute it and/or modify it
152             under the terms of the the Artistic License (2.0). You may obtain a
153             copy of the full license at:
154              
155             L
156              
157             Any use, modification, and distribution of the Standard or Modified
158             Versions is governed by this Artistic License. By using, modifying or
159             distributing the Package, you accept this license. Do not use, modify,
160             or distribute the Package, if you do not accept this license.
161              
162             If your Modified Version has been derived from a Modified Version made
163             by someone other than you, you are nevertheless required to ensure that
164             your Modified Version complies with the requirements of this license.
165              
166             This license does not grant you the right to use any trademark, service
167             mark, tradename, or logo of the Copyright Holder.
168              
169             This license includes the non-exclusive, worldwide, free-of-charge
170             patent license to make, have made, use, offer to sell, sell, import and
171             otherwise transfer the Package with respect to any patent claims
172             licensable by the Copyright Holder that are necessarily infringed by the
173             Package. If you institute patent litigation (including a cross-claim or
174             counterclaim) against any party alleging that the Package constitutes
175             direct or contributory patent infringement, then this Artistic License
176             to you shall terminate on the date that such litigation is filed.
177              
178             Disclaimer of Warranty: THE PACKAGE IS PROVIDED BY THE COPYRIGHT HOLDER
179             AND CONTRIBUTORS "AS IS' AND WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES.
180             THE IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
181             PURPOSE, OR NON-INFRINGEMENT ARE DISCLAIMED TO THE EXTENT PERMITTED BY
182             YOUR LOCAL LAW. UNLESS REQUIRED BY LAW, NO COPYRIGHT HOLDER OR
183             CONTRIBUTOR WILL BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, OR
184             CONSEQUENTIAL DAMAGES ARISING IN ANY WAY OUT OF THE USE OF THE PACKAGE,
185             EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
186              
187              
188             =cut
189              
190             1; # End of Net::Domain::Registration::Check