Debian Codegraph @

bin/get_root_domain

raw
1 #!/usr/bin/perl
2 use strict;
3 use warnings;
4 use Domain::PublicSuffix;
5
6 my $domain_name = shift(@ARGV);
7 usage('Requires a domain name to continue.') unless ( $domain_name );
8
9 my $suffix = Domain::PublicSuffix->new();
10
11 printf( "%12s: %s\n", 'Domain', $domain_name );
12 my $root_domain = $suffix->get_root_domain($domain_name);
13
14 if ( $suffix->error ) {
15 printf( "%12s: %s\n", 'Error', $suffix->error );
16 }
17 printf( "%12s: %s\n", 'Root Domain', $root_domain ) if ($root_domain);
18 printf( "%12s: %s\n", 'Suffix', $suffix->suffix ) if ($suffix->suffix);
19 printf( "%12s: %s\n", 'TLD', $suffix->tld ) if ($suffix->tld);
20
21
22 sub usage {
23 my ( $error ) = @_;
24
25 print "get_root_domain - Domain::PublicSuffix " . ($Domain::PublicSuffix::VERSION or 'dev') . "\n";
26 print "Usage: get_root_domain <domainname>\n";
27
28 exit(1);
29 }
30
31 1;
32
33 __END__
34
35 =head1 NAME
36
37 get_root_domain - Retrieve suffix info from a domain using Domain::PublicSuffix
38
39 =head1 DESCRIPTION
40
41 The get_root_domain utility uses Domain::PublicSuffix to get the root or
42 suffix for a fully qualified domain name. Given a FQDN, this utility will output
43 the "root domain", and the suffix and TLD used to calculate that root domain.
44
45 =over
46
47 =item * Public Info Site:
48
49 L<http://publicsuffix.org/>
50
51 =back
52
53 =head1 SYNOPSIS
54
55 get_root_domain <domainname>
56
57 =head1 EXAMPLE USAGE
58
59 =over
60
61 $ get_root_domain www.google.com
62 Domain: www.google.com
63 Root Domain: google.com
64 Suffix: com
65 TLD: com
66
67 $ get_root_domain www.google.co.uk
68 Domain: www.google.co.uk
69 Root Domain: google.co.uk
70 Suffix: co.uk
71 TLD: uk
72
73
74 =back
75
76 =head1 RETURN VALUES
77
78 Returns 0 if a successful lookup is done, non-zero otherwise.
79
80 =head1 SEE ALSO
81
82 Domain::PublicSuffix(3pm)
83
84 =head1 BUGS
85
86 Please report any bugs or feature requests to C<bug-domain-publicsuffix at rt.cpan.org>,
87 or through the web interface at L<http://rt.cpan.org/NoAuth/ReportBug.html?Queue=Domain-PublicSuffix>.
88 I will be notified, and then you'll automatically be notified of progress on
89 your bug as I make changes.
90
91 =head1 LICENSE
92
93 This program is free software; you can redistribute it and/or modify it
94 under the same terms as Perl itself.
95
96 =cut