| 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
| |||||||||||
| 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
| |||||||||||
| 33 | 1 | ▶ | printf("found %s\n", $flags) if $debug; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 34 | } | ||||||||||
| 35 | |||||||||||
| 36 | 1 | open (DNSQUERY, "$cmd $dnsquery $cmdargs |"); | |||||||||
| 37 | 1 | ▶ | while (<DNSQUERY>){ | ||||||||
|
Branch: 1 branch
| |||||||||||
| 38 | 0 | my $ln = $_; | |||||||||
| 39 | 0 | chomp($ln); | |||||||||
| 40 | 0 | ▶ | if( $ln =~ /Non-authoritative answer:/) { $wait = "n" } | ||||||||
|
Branch: 1 branch
| |||||||||||
| 41 | 0 | ▶ | next if ($wait eq "y"); | ||||||||
|
Branch: 1 branch
| |||||||||||
| 42 | 0 | $ct++; | |||||||||
| 43 | 0 | ▶ | printf("%s\n", $ln) if $debug; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 44 | 0 | ▶ | if($flags eq "u") { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 45 | # For *nix | ||||||||||
| 46 | 0 | ▶ | if($ln =~ /^Address:\s*(.*)$/) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 47 | 0 | ▶ | printf("%s\n", $1) if $debug; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 48 | 0 | $response = $response . $dnsquery.",".$1."\n"; | |||||||||
| 49 | } | ||||||||||
| 50 | } else { | ||||||||||
| 51 | # For win | ||||||||||
| 52 | 0 | ▶ | next if ($ct < 4); | ||||||||
|
Branch: 1 branch
| |||||||||||
| 53 | 0 | ▶ | if($ln =~ m/^Address:\s+(.*)$/) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 54 | 0 | $response = $response . $dnsquery.",".$1."\n"; | |||||||||
| 55 | } | ||||||||||
| 56 | 0 | ▶ | if($ln =~ m/^Addresses:\s+(.*)$/) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 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__ | ||||||||||