Git Product home page Git Product logo

Comments (2)

msimerson avatar msimerson commented on May 27, 2024

I've written quite a few scripts that automate the creation of forward and reverse matching DNS. The problem is, every single one has been unique to the organization using it. There just isn't a one-size-fits-all or even one-size-fits-most way to automatically create matching rDNS. There's an open issue #41 for doing it. Here's the salient bits of the last "add a host and matching IPv4 and IPv6 rDNS" script I wrote (but you'll notice, it has some extra not-included bits that determine what the right rDNS zone is):

$fqdn ||= $util->ask("fully qualified domain name (FQDN)");
$ip   ||= $util->ask("IPv4 address");
$ip6  ||= $util->ask("IPv6 address");       # get optional IPv6 IP

usage() if ( ! $fqdn || ( ! $ip && ! $ip6 ) );

$cnt->nt_connect();                         # connect to nictool

my ($host, $domain) = split /\./, $fqdn, 2; # get the $host / $domain
#print "host: $host\n";
#print "domn: $domain\n";

my $zone_id = $cnt->get_zone_id( $domain )  # find the $domain zone
    or die "could not find zone ID for $domain\n";

foreach my $t ( qw/ A AAAA / ) {

    my $now = $cnt->_get_zone_records( $zone_id, $host, $t ); # find the host record
    if ( $now ) {
        warn "$t record exists\n";
        my %new = %$now;
        $new{address} = $t eq 'A' ? $ip : $ip6;
        $cnt->update_record( \%new, $now );     # update the $host record
    }
    else {
        my $address = $t eq 'A' ? $ip : $ip6;
        if ( $address ) {
            $cnt->create_forward( $fqdn, $address, $t );
        };
    }
};

my $now = $cnt->get_reverse_zone_record($ip);  # find the reverse zone
if ( $now ) {
    my %new = %$now;
    $new{address} = "$fqdn.";
    $cnt->log( "updating PTR for $ip to $fqdn.\n" );
    $cnt->update_record( \%new, $now );           # update the PTR
};

if ( $ip6 && $ip6 ne '' ) {
    $now = $cnt->get_reverse_zone_record_ipv6($ip6);  # find the IPv6 reverse zone
    if ( $now ) {
# add IPv6 PTR
        my %new = %$now;
        $new{address} = "$fqdn.";
        $cnt->log( "updating PTR for $ip6 to $fqdn.\n" );
        $cnt->update_record( \%new, $now );           # update the PTR
    } 
    else {
        $cnt->create_ptr( $ip6, "$fqdn.");
    };
};

from nictool.

pertoft avatar pertoft commented on May 27, 2024

Thanks for the reply. It was very helpful!

I see you have cut'n'pasted from https://github.com/msimerson/NicTool/tree/master/server/api

The code is very helpful for me and ill try and brew a new clever script which interfaces to Nictool for reverse DNS management.

If i get it working, i will publish it here :)

Thanks
Per

from nictool.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.