line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
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
|
|
|
1
|
|
28407
|
use strict;
|
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
38
|
|
8
|
1
|
|
|
1
|
|
5
|
use vars qw($VERSION);
|
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
570
|
|
9
|
|
|
|
|
|
|
$VERSION = 0.03;
|
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
$|=1;
|
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
my $so = $^O;
|
14
|
|
|
|
|
|
|
my $cmd = "nslookup";
|
15
|
|
|
|
|
|
|
my $cmdargs = "";
|
16
|
|
|
|
|
|
|
my $debug;
|
17
|
|
|
|
|
|
|
my $flags;
|
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
if ($^O =~ /win/i) {
|
20
|
|
|
|
|
|
|
$flags = 'w';
|
21
|
|
|
|
|
|
|
$cmdargs = "2>&1";
|
22
|
|
|
|
|
|
|
} else {
|
23
|
|
|
|
|
|
|
$flags = 'u';
|
24
|
|
|
|
|
|
|
}
|
25
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
sub get_ips {
|
27
|
1
|
|
|
1
|
1
|
11
|
my $response = "";
|
28
|
1
|
|
|
|
|
2
|
my $dnsquery = $_[1];
|
29
|
1
|
|
|
|
|
2
|
my $wait = "y";
|
30
|
1
|
|
|
|
|
2
|
my $ct = 0;
|
31
|
|
|
|
|
|
|
|
32
|
1
|
50
|
|
|
|
3
|
if($flags eq "u") {
|
33
|
1
|
50
|
|
|
|
3
|
printf("found %s\n", $flags) if $debug;
|
34
|
|
|
|
|
|
|
}
|
35
|
|
|
|
|
|
|
|
36
|
1
|
|
|
|
|
9479
|
open (DNSQUERY, "$cmd $dnsquery $cmdargs |");
|
37
|
1
|
|
|
|
|
200
|
while (){
|
38
|
0
|
|
|
|
|
0
|
my $ln = $_;
|
39
|
0
|
|
|
|
|
0
|
chomp($ln);
|
40
|
0
|
0
|
|
|
|
0
|
if( $ln =~ /Non-authoritative answer:/) { $wait = "n" }
|
|
0
|
|
|
|
|
0
|
|
41
|
0
|
0
|
|
|
|
0
|
next if ($wait eq "y");
|
42
|
0
|
|
|
|
|
0
|
$ct++;
|
43
|
0
|
0
|
|
|
|
0
|
printf("%s\n", $ln) if $debug;
|
44
|
0
|
0
|
|
|
|
0
|
if($flags eq "u") {
|
45
|
|
|
|
|
|
|
# For *nix
|
46
|
0
|
0
|
|
|
|
0
|
if($ln =~ /^Address:\s*(.*)$/) {
|
47
|
0
|
0
|
|
|
|
0
|
printf("%s\n", $1) if $debug;
|
48
|
0
|
|
|
|
|
0
|
$response = $response . $dnsquery.",".$1."\n";
|
49
|
|
|
|
|
|
|
}
|
50
|
|
|
|
|
|
|
} else {
|
51
|
|
|
|
|
|
|
# For win
|
52
|
0
|
0
|
|
|
|
0
|
next if ($ct < 4);
|
53
|
0
|
0
|
|
|
|
0
|
if($ln =~ m/^Address:\s+(.*)$/) {
|
54
|
0
|
|
|
|
|
0
|
$response = $response . $dnsquery.",".$1."\n";
|
55
|
|
|
|
|
|
|
}
|
56
|
0
|
0
|
|
|
|
0
|
if($ln =~ m/^Addresses:\s+(.*)$/) {
|
57
|
0
|
|
|
|
|
0
|
my $t = $1;
|
58
|
0
|
|
|
|
|
0
|
$t =~ s/ //g;
|
59
|
0
|
|
|
|
|
0
|
my @t = split(/,/, $t);
|
60
|
0
|
|
|
|
|
0
|
foreach (@t) {
|
61
|
0
|
|
|
|
|
0
|
$response = $response . $dnsquery.",".$_."\n";
|
62
|
|
|
|
|
|
|
}
|
63
|
|
|
|
|
|
|
}
|
64
|
|
|
|
|
|
|
}
|
65
|
|
|
|
|
|
|
}
|
66
|
1
|
|
|
|
|
6
|
close DNSQUERY;
|
67
|
1
|
|
|
|
|
15
|
chomp $response;
|
68
|
1
|
|
|
|
|
31
|
return $response;
|
69
|
|
|
|
|
|
|
}
|
70
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
1;
|
72
|
|
|
|
|
|
|
__END__
|