User Tools

Site Tools


dns_add_script

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

dns_add_script [2009/08/14 20:45]
jt created
dns_add_script [2020/08/10 02:35]
Line 1: Line 1:
-<code perl> 
  
-#​!/​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";​ 
- 
-} 
- 
- 
-</​code>​ 
dns_add_script.txt ยท Last modified: 2020/08/10 02:35 (external edit)