How to update DNS record
andi.clemens at gmx.net
andi.clemens at gmx.net
Thu Mar 1 10:37:25 EST 2007
Hi,
I'm just a trainee working here and I don't really know how the old
Perl script worked.
But I can post the function, maybe you can recognize what is going on
there:
my $domain = "wiv-dom.com";
my $nameserver = "bldc01.wiv-dom.com";
sub makeDNSEntry {
my $res = new Net::DNS::Resolver;
my $query = $res->query("$domain", "NS");
if ($query) {
print "\nMaking entries into nameserver...\nSearching for
nameservers...\n\n" if $opt{d};
foreach my $rr ($query->answer) {
next unless $rr->type eq "NS";
print $rr->nsdname, "\n" if $opt{d};
}
}
else {
print "query for Nameserver for $domain failed: ", $res-
>errorstring, "\n";
}
my $update = new Net::DNS::Update("$domain");
$update->push("pre", yxrrset("$snmpHostName.$domain. A"));
$update->push("update", rr_del("$snmpHostName.$domain. A"));
$update->push("update", rr_add("$snmpHostName.$domain. 3600 A
$outbound"));
$res = new Net::DNS::Resolver;
$res->nameservers("$nameserver");
print "\nNameserver for $domain :" . $nameserver, "\n" if $opt{d};
my $reply = $res->send($update);
if (defined $reply) {
if ($reply->header->rcode eq "NOERROR") {
print "Update for $snmpHostName.$domain. OK\n" if $opt{d};
} else {
print "Update for $snmpHostName.$domain. ERROR : ". $reply-
>header->rcode. "\n" if $opt{d};
}
} else {
print "RESERROR : No reply: ". $res->errorstring. "\n";
}
}
What I want to do is change the A-Record of existing entries in the
DNS server.
I'm getting all the IPs from a django database and ask them via SNMP
what their outbound address is, then I want to change those settings
in our DNS server like in the perl script above.
Sorry for my bad explanation, but I never worked with DNS before...
Andi
More information about the Python-list
mailing list