Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/env perl
- use strict;
- use warnings;
- use feature qw(say);
- use Text::CSV;
- my $csv = Text::CSV->new({ sep_char => ',' });
- my $outfile = 'resolvers.csv';
- open(my $fh, '>', $outfile) or die "Cannot create $outfile, $!\n";
- my $file = $ARGV[0] or die "Need to get CSV file on the command line\n";
- open(my $data, '<', $file) or die "Could not open '$file' $!\n";
- my $linenumber = 0;
- while (my $line = <$data>) {
- chomp $line;
- $linenumber += 1;
- if ($linenumber < 2) {
- print "$linenumber: Resolver address\n";
- print $fh "$line\n";
- } elsif ($csv->parse($line)) {
- my @fields = $csv->fields();
- # NOT IP6 AND (ends in :53, :443, :2053 ,:5353 OR ends like IP4)
- if ($fields[10] !~ m/^\[/ and ($fields[10] =~ m/:443$|:2053$|:5353$|:53$/ or $fields[10] =~ m/\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}$/)) {
- print "$linenumber: $fields[10]\n";
- print $fh "$line\n"
- }
- } else {
- # be quiet
- }
- }
- close $fh or die "Error in closing the file ", __FILE__, " $!\n";
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement