⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 h2n

📁 早期freebsd实现
💻
📖 第 1 页 / 共 2 页
字号:
# Establish what we will be using for SOA records#sub FIXUP {    local($s);    if ($Host =~ /\./) {	$RespHost = "$Host.";    } else {	$RespHost = "$Host.$Domain.";    }    $RespHost =~ s/\.\././g;    if ($User =~ /@/) {				# -u user@...	if ($User =~ /\./) {	    $RespUser = "$User.";		# -u user@terminator.movie.edu	} else {	    $RespUser = "$User.$Domain."; 	# -u user@terminator	}	$RespUser =~ s/@/./;    } elsif ($User =~ /\./) {	$RespUser = "$User.";			# -u user.terminator.movie.edu    } else {	$RespUser = "$User.$RespHost";		# -u user    }    $RespUser =~ s/\.\././g;			# Strip any ".."'s to "."    # Clean up nameservers    if (!defined(@Servers)) {	push(@Servers, "$Host.$Domain.");    } else {	foreach $s (@Servers) {	    if ($s !~ /\./) {		$s .= ".$Domain";	    }	    if ($s !~ /\.$/) {		$s .= ".";	    }	}    }    # Clean up MX hosts    foreach $s (@Mx) {	$s =~ s/:/ /;	if ($s !~ /\./) {	    $s .= ".$Domain";	}	if ($s !~ /\.$/) {	    $s .= ".";	}    }    # Now open boot file and print saved data    open(BOOT, "> $Bootfile")  || die "can not open $Bootfile";    print BOOT "\ndirectory $Pwd\n";    foreach $line (@bootmsgs) {	print BOOT $line;    }    print BOOT "cache\t. db.cache\n";    # Go ahead and start creating files and making SOA's    foreach $i (@makesoa) {	($x1, $x2) = split(' ', $i);	&MAKE_SOA($x1, $x2);    }    printf DOMAIN "%-20s IN  A     127.0.0.1\n", "localhost";        $file = "DB.127.0.0.1";    &MAKE_SOA("db.127.0.0", $file);    printf $file "%-30s\tIN  PTR   localhost.\n", &REVERSE("127.0.0.1");    close($file);}sub PARSEARGS {    local(@args) = @_;    local($i, $net, $subnetmask, $option, $tmp1);    local(*F, $file, @newargs, @targs);    $i = 0;    while ($i <= $#args){	$option = $args[$i];	if($option eq "-d"){	    $Domain = $args[++$i];	    $Domainpattern = "." . $Domain;	    $Domainpattern =~ s/\./\\./g;        # for stripping off domain	    # Add entry to the boot file.	    $Domainfile = $Domain;	    $Domainfile =~ s/\..*//;	    push(@makesoa, "db.$Domainfile DOMAIN");	    push(@bootmsgs, "primary\t$Domain db.$Domainfile\n");	} elsif ($option eq "-f"){	    $file = $args[++$i];	    open(F, $file) || die "Unable to open args file $file: $!";	    while (<F>) {		next if (/^#/);		next if (/^$/);		chop;		@targs = split(' ');		push(@newargs, @targs);	    }	    close(F);	    &PARSEARGS(@newargs);	} elsif ($option eq "-z"){	    $Bootsecsaveaddr = $args[++$i];	    if (!defined($Bootsecaddr)) {		$Bootsecaddr = $Bootsecsaveaddr;	    }	} elsif ($option eq "-Z"){	    $Bootsecaddr = $args[++$i];	    if (!defined($Bootsecsaveaddr)) {		$Bootsecsaveaddr = $Bootsecaddr;	    }	} elsif ($option eq "-b"){	    $Bootfile = $args[++$i];	} elsif ($option eq "-A"){	    $doaliases = 0;	} elsif ($option eq "-M"){	    $domx = 0;	} elsif ($option eq "-w"){	    $dowks = 1;	} elsif ($option eq "-D"){	    $dontdodomains = 1;	} elsif ($option eq "-t"){	    $dotxt = 1;	} elsif ($option eq "-u"){	    $User = $args[++$i];	} elsif ($option eq "-s"){	    while ($args[++$i] !~ /^-/ && $i <= $#args) {		push(@Servers, $args[$i]);	    }	    $i--;	} elsif ($option eq "-m"){	    if ($args[++$i] !~ /:/) {		print STDERR "Improper format for -m option ignored ($args[$i]).\n";	    }	    push(@Mx, $args[$i]);	} elsif ($option eq "-c"){	    $tmp1 = $args[++$i];	    if ($tmp1 !~ /\./) {		$tmp1 .= ".$Domain";	    }	    $tmp2 = $tmp1;	    $tmp2 =~ s/\./\\./g; 	    $cpatrel{$tmp2} = $tmp1;	    push(@cpats, $tmp2);	} elsif ($option eq "-e"){	    $tmp1 = $args[++$i];	    if ($tmp1 !~ /\./) {		$tmp1 .= ".$Domain";	    }	    $tmp1 =~ s/\./\\./g; 	    push(@elimpats, $tmp1);	} elsif ($option eq "-h"){	    $Host = $args[++$i];	} elsif ($option eq "-o"){	    if (   $args[++$i] !~ /^[:\d]*$/ 		|| split(':', $args[$i]) != 4) {		print STDERR "Improper format for -o ($args[$i]).\n";		print STDERR "I give up ... sorry.\n";		exit(1);	    }	    ($DefRefresh, $DefRetry, $DefExpire, $DefTtl) = split(':', $args[$i]);	} elsif ($option eq "-i"){	    $ForceSerial = $args[++$i];	} elsif ($option eq "-H"){	    $Hostfile = $args[++$i];	    if (! -r $Hostfile || -z $Hostfile) {		print STDERR "Invalid file specified for -H ($Hostfile).\n";		print STDERR "I give up ... sorry.\n";		exit(1);	    }	} elsif ($option eq "-C"){	    $Commentfile = $args[++$i];	    if (! -r $Commentfile || -z $Commentfile) {		print STDERR "Invalid file specified for -C ($Commentfile).\n";		print STDERR "I give up ... sorry.\n";		exit(1);	    }	} elsif ($option eq "-N"){	    $Defsubnetmask = $args[++$i];	    if (   $Defsubnetmask !~ /^[.\d]*$/ 		|| split('\.', $Defsubnetmask) != 4) {		print STDERR "Improper subnet mask ($Defsubnetmask).\n";		print STDERR "I give up ... sorry.\n";		exit(1);	    }	    if ($#Networks >= 0) {		print STDERR "Hmm, -N option should probably be specified before any -n options.\n";	    }	} elsif ($option eq "-n"){	    ($net, $subnetmask) = split(':',$args[++$i]);	    if ($subnetmask eq "") {		foreach $tmp1 (&SUBNETS($net, $Defsubnetmask)) {		    &BUILDNET($tmp1);		}	    } else {		if (   $subnetmask !~ /^[.\d]*$/ 		    || split('\.', $subnetmask) != 4) {		    print STDERR "Improper subnet mask ($subnetmask).\n";		    print STDERR "I give up ... sorry.\n";		    exit(1);		}		foreach $tmp1 (&SUBNETS($net, $subnetmask)) {		    &BUILDNET($tmp1);		}	    }	} elsif ($option eq "-1"){	    print STDERR "Option -1 is obsolete ... ignored.\n";	} elsif ($option eq "-F"){	    print STDERR "Option -F is now the default (and only) way ... ignored.\n";	} else {	    if($option =~ /^-.*/){		print STDERR "Unknown option: $option ... ignored.\n";	    }	}	$i++;    }        if (!defined(@Networks) || $Domain eq "") {	print STDERR "Must specify at least -d and one -n.\n";	print STDERR "I give up ... sorry.\n";	exit(1);    }}sub BUILDNET {    local($net) = @_;    push(@Networks, $net);    #    # Create pattern to match against.      # The dots must be changed to \. so they     # aren't used as wildcards.    #    $netpat = $net;    $netpat =~ s/\./\\./g;    push(@Netpatterns, $netpat);    #    # Create db files for PTR records.    # Save the file names in an array for future use.    #    $netfile = "DB.$net";    $Netfiles{$netpat} = $netfile;    push(@makesoa, "db.$net $netfile");    # Add entry to the boot file.    $revaddr = &REVERSE($net);    chop($revaddr);   # remove trailing dot    push(@bootmsgs, "primary $revaddr db.$net\n");}## Calculate all the subnets from a network number and mask.# This was originally written for awk, not perl.#sub SUBNETS {    local($network, $mask) = @_;    local(@ans, @net, @mask, $buf, $number, $i, $j, $howmany);    @net = split(/\./, $network);    @mask = split(/\./, $mask);    $number = '';    #    # Only expand bytes 1, 2, or 3    # for DNS purposes    #    for ($i = 0; $i < 3; $i++) {	if ($mask[$i] == 255) {	    $number = $number . $net[$i] . '.';	} elsif (($mask[$i] == 0) || $mask[$i] eq '') {	    push(@ans, $network);	    last;	} else {	    #	    # This should be done as a bit-wise or	    # but awk does not have an or symbol	    #	    $howmany = 255 - $mask[$i];	    for ($j = 0; $j <= $howmany; $j++) {		if ($net[$i] + $j <= 255) {		    $buf = sprintf("%s%d", $number, $net[$i] + $j);		    push(@ans, $buf);		}	    }	    last;	}    }    if ($#ans == -1) {	push(@ans, $network);    }        @ans;}sub GEN_BOOT {    local(*F, $revaddr, $n);    if (! -e "boot.cacheonly") {	open(F, ">boot.cacheonly") || die "Unable to open boot.cacheonly: $!";	print F "directory\t$Pwd\n";	print F "primary\t\t0.0.127.IN-ADDR.ARPA    db.127.0.0\n";	print F "cache\t\t.                       db.cache\n";	close(F);    }        if (defined($Bootsecaddr)) {	open(F, ">boot.sec") || die "Unable to open boot.sec: $!";	print  F "directory\t$Pwd\n";	print  F "primary\t\t0.0.127.IN-ADDR.ARPA    db.127.0.0\n";	printf F "secondary\t%-23s $Bootsecaddr\n", $Domain;	foreach $n (@Networks) {	    $revaddr = &REVERSE($n);	    chop($revaddr);	    printf F "secondary\t%-23s $Bootsecaddr\n", $revaddr;	}	print  F "cache\t\t.                       db.cache\n";	close(F);	open(F, ">boot.sec.save") || die "Unable to open boot.sec.save: $!";	print  F "directory\t$Pwd\n";	print  F "primary\t\t0.0.127.IN-ADDR.ARPA    db.127.0.0\n";	printf F "secondary\t%-23s $Bootsecsaveaddr db.%s\n", 	       $Domain, $Domainfile;	foreach $n (@Networks) {	    $revaddr = &REVERSE($n);	    chop($revaddr);	    printf F "secondary\t%-23s $Bootsecsaveaddr db.%s\n", 		   $revaddr, $n;	}	print  F "cache\t\t.                       db.cache\n";	close(F);    }}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -