User Tools

Site Tools


dns_add_script

This is an old revision of the document!


#!/usr/bin/perl -w
##Jason Thomas
use strict;
use File::Copy;
use IO::File;
##use Text::Template;
 
my $entry;
my $hostName;
my $ipAddress;
my $domainName;
my $subDomain;
my $dbZoneFile;
my $repository = "/home/jthomas/dns/master";
my $dnsData = "data";
open (DATA, $dnsData), or die $!;
my @dnsLine = <DATA>;
 
foreach $entry (@dnsLine){
 
	chomp ($entry);
	($hostName, $ipAddress) = split(' ', $entry);
	$subDomain = findDomainName($hostName);
##	print "$domainName\n";
	checkZoneExist($domainName);
 
	if ( defined($subDomain) &&  $subDomain ne "www"){
	addToZone($dbZoneFile, $subDomain, $ipAddress);
	}
}
 
close (DATA);
 
exit (0);
 
sub findDomainName{
 
	my $hostName = shift;
	my $subDomain;
	my $size;
	my $counter;
	my @tmp;
 
	@tmp = split('\.', $hostName);
	$size = @tmp - 2; 
##	print "size of array: $size.\n";
 
		if ( @tmp==2){
			$domainName = "$tmp[0].$tmp[1]";
			return undef;
##		print "$domainName\n";
		}
		else{
			$domainName = "$tmp[@tmp-2].$tmp[@tmp-1]";
 
			for ($counter = 0; $counter < $size; $counter++){
 
				if ( ! defined($subDomain) ){
					$subDomain=$tmp[$counter];
				}
				else{
					$subDomain="$subDomain.$tmp[$counter]";
				}
			}
##			print "$subDomain.$domainName\n";
			return $subDomain;
		}
}
 
sub checkZoneExist{
 
	my $domainName = shift;
	my $dbZoneFile = "db.$domainName";
 
		if ( -e $repository.$dbZoneFile ){
		##	print "$dbZoneFile exists\n";
		}
		else{
		##	print "$dbZoneFile does not exists\n";	
		}
 
	return $dbZoneFile;
 
 
}
 
sub makeZone{
 
 
 
 
}
 
sub addToZone{
 
	$dbZoneFile = shift; 
	$subDomain = shift;
	$ipAddress = shift;
 
	print "$subDomain\t\tIN\tA\t$ipAddress\n";
 
}
dns_add_script.1250282756.txt.gz · Last modified: 2020/08/10 02:28 (external edit)