1#! @PERL@ 2# 3# Perl script to sort DNS names 4# 5 6# ************************************************************************* 7# * Copyright © 2004-2006 Rémi Denis-Courmont. * 8# * This program is free software: you can redistribute and/or modify * 9# * it under the terms of the GNU General Public License as published by * 10# * the Free Software Foundation, versions 2 or 3 of the license. * 11# * * 12# * This program is distributed in the hope that it will be useful, * 13# * but WITHOUT ANY WARRANTY; without even the implied warranty of * 14# * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * 15# * GNU General Public License for more details. * 16# * * 17# * You should have received a copy of the GNU General Public License * 18# * along with this program. If not, see <http://www.gnu.org/licenses/>. * 19# ************************************************************************* 20 21use strict; 22#use locale; -- not very useful for DNS 23use Getopt::Std; 24 25$Getopt::Std::STANDARD_HELP_VERSION = 1; 26$main::VERSION = '@VERSION@'; 27 28sub main::HELP_MESSAGE() 29{ 30 print "Usage: dnssort [-r] [FILES]\n". 31 " Sorts DNS hostnames from input.\n"; 32} 33 34 35# Parse command line 36our $opt_r; 37getopts('r'); 38 39if ($#ARGV < 0) 40{ 41 # No files specified -> Use standard input 42 push @ARGV, '-'; 43} 44 45# Read files 46my @names = (); 47 48foreach (@ARGV) 49{ 50 open FD,"< $_" or die "$_: $!\n"; 51 while(<FD>) 52 { 53 chomp; 54 push @names, join('.', reverse split /\./); 55 } 56 close FD; 57} 58 59# Sort entries 60@names = sort { lc($a) cmp lc($b) } @names; 61if ($opt_r) 62{ 63 @names = reverse @names; 64} 65 66# Print results 67foreach (@names) 68{ 69 print join('.', reverse split /\./)."\n"; 70} 71 72