Advertisement
Guest User

Untitled

a guest
Feb 28th, 2017
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.00 KB | None | 0 0
  1. #!/usr/bin/env perl
  2.  
  3. use strict;
  4. use warnings;
  5. use feature qw(say);
  6.  
  7. use Text::CSV;
  8. my $csv = Text::CSV->new({ sep_char => ',' });
  9.  
  10. my $outfile = 'resolvers.csv';
  11. open(my $fh, '>', $outfile) or die "Cannot create $outfile, $!\n";
  12.  
  13. my $file = $ARGV[0] or die "Need to get CSV file on the command line\n";
  14. open(my $data, '<', $file) or die "Could not open '$file' $!\n";
  15.  
  16. my $linenumber = 0;
  17. while (my $line = <$data>) {
  18. chomp $line;
  19. $linenumber += 1;
  20. if ($linenumber < 2) {
  21. print "$linenumber: Resolver address\n";
  22. print $fh "$line\n";
  23. } elsif ($csv->parse($line)) {
  24. my @fields = $csv->fields();
  25. # NOT IP6 AND (ends in :53, :443, :2053 ,:5353 OR ends like IP4)
  26. 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}$/)) {
  27. print "$linenumber: $fields[10]\n";
  28. print $fh "$line\n"
  29. }
  30. } else {
  31. # be quiet
  32. }
  33. }
  34. close $fh or die "Error in closing the file ", __FILE__, " $!\n";
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement