blib/lib/Net/DNS/Nslookup.pm

filter: Statementstmt 54.1% 26 / 48 Branchbran 15.3% 4 / 26 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 3 / 3 Podpod 100% 1 / 1 totaltotal 43.5% 34 / 78 CC 14 SCAR 44.2
CC
14
Cov
41%
get_ips
95.2
BEGIN
1.0
BEGIN
1.0
CRAP 83.4
↑ Summary
1 package Net::DNS::Nslookup;
2
3 # Copyright (c) 2011 Paul Greenberg. All rights reserved.
4 # This program is free software; you can redistribute it
5 # and/or modify it under the same terms as Perl itself.
6
7 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 1 ▶use vars qw($VERSION);
Subroutine BEGIN: called CC=1 SCAR=0.0
9 1 $VERSION = 0.03;
10
11 1 $|=1;
12
13 1 my $so = $^O;
14 1 my $cmd = "nslookup";
15 1 my $cmdargs = "";
16 1 my $debug;
17 my $flags;
18
19 1 ▶if ($^O =~ /win/i) {
Branch: 1 branch
BranchTrueFalseTotal
if ($^O =~ /win/i) { } 0 1 1
20 0 $flags = 'w';
21 0 $cmdargs = "2>&1";
22 } else {
23 1 $flags = 'u';
24 }
25
26 1 ▶sub get_ips {
Subroutine get_ips: called CC=14 SCAR=45.6
Pod documented
27 1 my $response = "";
28 1 my $dnsquery = $_[1];
29 1 my $wait = "y";
30 1 my $ct = 0;
31
32 1 ▶ if($flags eq "u") {
Branch: 1 branch
BranchTrueFalseTotal
if ($flags eq "u") 1 0 1
33 1 ▶ printf("found %s\n", $flags) if $debug;
Branch: 1 branch
BranchTrueFalseTotal
if $debug 0 1 1
34 }
35
36 1 open (DNSQUERY, "$cmd $dnsquery $cmdargs |");
37 1 ▶ while (<DNSQUERY>){
Branch: 1 branch
BranchTrueFalseTotal
if (defined($_ = readline DNSQUERY)) 0 1 1
38 0 my $ln = $_;
39 0 chomp($ln);
40 0 ▶ if( $ln =~ /Non-authoritative answer:/) { $wait = "n" }
Branch: 1 branch
BranchTrueFalseTotal
if ($ln =~ /Non-authoritative answer:/) 0 0 0
41 0 ▶ next if ($wait eq "y");
Branch: 1 branch
BranchTrueFalseTotal
if $wait eq "y" 0 0 0
42 0 $ct++;
43 0 ▶ printf("%s\n", $ln) if $debug;
Branch: 1 branch
BranchTrueFalseTotal
if $debug 0 0 0
44 0 ▶ if($flags eq "u") {
Branch: 1 branch
BranchTrueFalseTotal
if ($flags eq 'u') { } 0 0 0
45 # For *nix
46 0 ▶ if($ln =~ /^Address:\s*(.*)$/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($ln =~ /^Address:\s*(.*)$/) 0 0 0
47 0 ▶ printf("%s\n", $1) if $debug;
Branch: 1 branch
BranchTrueFalseTotal
if $debug 0 0 0
48 0 $response = $response . $dnsquery.",".$1."\n";
49 }
50 } else {
51 # For win
52 0 ▶ next if ($ct < 4);
Branch: 1 branch
BranchTrueFalseTotal
if $ct < 4 0 0 0
53 0 ▶ if($ln =~ m/^Address:\s+(.*)$/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($ln =~ /^Address:\s+(.*)$/) 0 0 0
54 0 $response = $response . $dnsquery.",".$1."\n";
55 }
56 0 ▶ if($ln =~ m/^Addresses:\s+(.*)$/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($ln =~ /^Addresses:\s+(.*)$/) 0 0 0
57 0 my $t = $1;
58 0 $t =~ s/ //g;
59 0 my @t = split(/,/, $t);
60 0 foreach (@t) {
61 0 $response = $response . $dnsquery.",".$_."\n";
62 }
63 }
64 }
65 }
66 1 close DNSQUERY;
67 1 chomp $response;
68 1 return $response;
69 }
70
71 1 1;
72 __END__
↑ Summary