DNS cheatsheet: Difference between revisions
From Lolly's Wiki
Jump to navigationJump to search
(Die Seite wurde neu angelegt: „==dns2hosts== <source lang=perl> #!/usr/bin/perl use Net::DNS; use Net::DNS qw(rrsort); my @nameservers = ("auth-dns-1.domain.de","auth-dns-2.domain.de"); my…“) |
No edit summary |
||
Line 1: | Line 1: | ||
=dig= | |||
==Compare several nameserver if SOA matches== | |||
<source lang=bash> | |||
$ domain=denic.de | |||
$ printf "Domain: %s\n" ${domain} ; for ns in $(dig +short ${domain} ns) ; do printf "Nameserver: %s => SOA: %s\n" ${ns} "$(dig +short ${domain} soa @${ns})" ; done | |||
Domain: denic.de | |||
Nameserver: ns2.denic.de. => SOA: ns1.denic.de. its.denic.de. 1468491003 10800 1800 3600000 1800 | |||
Nameserver: ns1.denic.de. => SOA: ns1.denic.de. its.denic.de. 1468491003 10800 1800 3600000 1800 | |||
Nameserver: ns3.denic.de. => SOA: ns1.denic.de. its.denic.de. 1468491003 10800 1800 3600000 1800 | |||
</source> | |||
==dns2hosts== | ==dns2hosts== | ||
<source lang=perl> | <source lang=perl> |
Revision as of 06:57, 15 July 2016
dig
Compare several nameserver if SOA matches
$ domain=denic.de
$ printf "Domain: %s\n" ${domain} ; for ns in $(dig +short ${domain} ns) ; do printf "Nameserver: %s => SOA: %s\n" ${ns} "$(dig +short ${domain} soa @${ns})" ; done
Domain: denic.de
Nameserver: ns2.denic.de. => SOA: ns1.denic.de. its.denic.de. 1468491003 10800 1800 3600000 1800
Nameserver: ns1.denic.de. => SOA: ns1.denic.de. its.denic.de. 1468491003 10800 1800 3600000 1800
Nameserver: ns3.denic.de. => SOA: ns1.denic.de. its.denic.de. 1468491003 10800 1800 3600000 1800
dns2hosts
#!/usr/bin/perl
use Net::DNS;
use Net::DNS qw(rrsort);
my @nameservers = ("auth-dns-1.domain.de","auth-dns-2.domain.de");
my $net_regex = '10\.11\.';
my $domain = 'domain.de';
# cut_off_domain=0 : host.domain
# cut_off_domain=1 : short name only
# cut_off_domain=2 : short name and with domain
my $cut_off_domain=1;
my $res = Net::DNS::Resolver->new;
$res->nameservers(@nameservers);
Net::DNS::RR::A->set_rrsort_func ('asorted',
sub {($a,$b)=($Net::DNS::a,$Net::DNS::b);
$a->{'address'} cmp $b->{'address'}});
# Get the zone
my @zone = $res->axfr($domain);
# All A records
my @addresses = grep { $_->type eq "A" } @zone;
# Filter out net if $net_regex is set
@addresses = grep { $_->address =~ /$net_regex/ } @addresses if(defined($net_regex));
# All CNAME records
my @cnames = grep { $_->type eq "CNAME" } @zone;
my $host;
foreach $rr (rrsort("A","asorted", @addresses)) {
$host=$rr->name;
$host=(split /\./,$host)[0] if ($cut_off_domain eq 1);
$host=(split /\./,$rr->name)[0]." ".$rr->name if ($cut_off_domain eq 2);
print $rr->address."\t".$host;
foreach $cname (grep { $_->cname eq $rr->name } @cnames) {
$host=$cname->name;
$host=(split /\./,$host)[0] if ($cut_off_domain eq 1);
$host=(split /\./,$cname->name)[0]." ".$cname->name if ($cut_off_domain eq 2);
print " ".$host;
}
print "\n";
}