Path: utzoo!utgpu!news-server.csri.toronto.edu!rpi!zaphod.mps.ohio-state.edu!uakari.primate.wisc.edu!aplcen!boingo.med.jhu.edu!haven!ni.umd.edu!sayshell.umd.edu!louie From: louie@sayshell.umd.edu (Louis A. Mamakos) Newsgroups: comp.lang.perl Subject: Re: named -> hosts code anyone? Message-ID: <1991Apr11.035709.15479@ni.umd.edu> Date: 11 Apr 91 03:57:09 GMT References: Sender: usenet@ni.umd.edu (USENET News System) Organization: University of Maryland, College Park Lines: 95 Nntp-Posting-Host: sayshell.umd.edu I have a perl script that's pretty close. It take domain zone file and turns them into HOSTS.TXT formatted file; you can then run htable if you want /etc/hosts flavored files. This is really, really old perl code, some of my first. It seems to work for us, and I've never got around to cleaning it up any. louie #!/usr/local/bin/perl # $host = ''; $addr = ''; $machine = ''; $opsys = ''; $services = ''; $origin = ''; loop: while(<>) { chop; if (/.*\($/) { $foo = $_; paren: while (<>) { chop; $foo .= $_; if ($foo =~ /\)$/) { last paren; } } $_ = $foo; } # # if the beginning of the line is blank, then substitute the last # hostname used. # s/^([ \t])(.*)$/$host\t$2/; @rr = split; if ( $rr[0] eq '$ORIGIN' ) { if ( $rr[1] !~ /\.$/ ) { $origin = $rr[1] . '.' . $origin; $origin =~ s/\.\./\./g; $origin =~ s/(..*)\.$/$1/; printf "; new origin (rel) %s\n", $origin; } else { $origin = $rr[1]; $origin =~ s/(..*)\.$/$1/; printf "; new origin %s\n", $origin; } next loop; } if ( $rr[1] ne 'IN' ) { printf ";; %s\n", $_; next loop; } next if ($rr[2] eq "CNAME" ); next if ($rr[2] eq "NS" ); if ($rr[2] eq "SOA" ) { printf ";\n; domain %s zone transfer, zone serial number %s\n", $rr[0] . '.' . $origin, $rr[7]; printf "; created %s;\n", `date`; next loop; } if ( $host ne $rr[0] ) { if ($addr && $host) { printf "HOST : %s : %s : %s : %s : : \n", $addr, $hostname, $machine, $opsys; } $addr = ''; $machine = ''; $services = ''; $opsys = ''; $host = $rr[0]; $hostname = $host . "." . $origin; $hostname =~ s/^(.*)\.$/$1/ ; } if ($rr[2] eq "A" ) { $addr = $rr[3]; next; } if ($rr[2] eq "HINFO" ) { $rr[3] =~ s/^\"(.*)\"$/$1/; # strip off quotes $rr[4] =~ s/^\"(.*)\"$/$1/; $machine = $rr[3]; $opsys = $rr[4]; next; } } if ($addr) { printf "HOST : %s : %s : %s : %s : %s : \n", $addr, $hostname, $machine, $opsys, $services; }