From bacchus.pa.dec.com!decwrl!uunet!allbery Tue Oct 16 20:21:35 PDT 1990 Article: 1912 of comp.sources.misc Path: bacchus.pa.dec.com!decwrl!uunet!allbery From: aem@mthvax.cs.miami.edu (a.e.mossberg) Newsgroups: comp.sources.misc Subject: v15i080: makehosts - Convert BIND hosts tables to /etc/hosts table Message-ID: <108631@uunet.UU.NET> Date: 15 Oct 90 01:47:21 GMT Sender: allbery@uunet.UU.NET Lines: 266 Approved: allbery@uunet.UU.NET (Brandon S. Allbery - comp.sources.misc) X-UNIX-From: aem@mthvax.cs.miami.edu Posting-number: Volume 15, Issue 80 Submitted-by: "a.e.mossberg" Archive-name: makehosts/part01 This is a little perl utility I whipped up to convert BIND hosts files into /etc/hosts file format. I make to attempt to handle cname records, or anything like that. It's quick, easy, and it works for me. ciao andrew mossberg, university of miami dept of mathematics and computer science ---------------------------cut here----------------------------- #! /bin/sh # This is a shell archive, meaning: # 1. Remove everything above the #! /bin/sh line. # 2. Save the resulting text in a file. # 3. Execute the file with /bin/sh (not csh) to create the files: # README # makehosts # hosts.sample.input # hosts.sample.extra # Makefile # This archive created: Sat Oct 6 16:32:30 1990 export PATH; PATH=/bin:$PATH echo shar: extracting "'README'" '(294 characters)' if test -f 'README' then echo shar: will not over-write existing file "'README'" else cat << \SHAR_EOF > 'README' This is a little perl utility I whipped up to convert BIND hosts files into /etc/hosts file format. I make to attempt to handle cname records, or anything like that. It's quick, easy, and it works for me. ciao andrew mossberg, university of miami dept of mathematics and computer science SHAR_EOF fi # end of overwriting check echo shar: extracting "'makehosts'" '(1240 characters)' if test -f 'makehosts' then echo shar: will not over-write existing file "'makehosts'" else cat << \SHAR_EOF > 'makehosts' #!/usr/local/bin/perl # $Header: /tempf/aem/makehosts/makehosts,v 1.1 90/10/06 16:14:52 aem Exp $ if ( $ENV{'USER'} ) { $whoami = $ENV{'USER'}; } else { $whoami = `whoami`; chop ($whoami); } if ( $ENV{'HOSTNAME'} ) { $hostname = $ENV{'HOSTNAME'}; } else { $hostname = `hostname`; chop ($hostname); } $date = `date`; print "\#\n\# This file created from nameserver tables\n"; print "\#\tby $whoami\n\#\tat $hostname\n\#\ton $date\#\n"; while (<>) { ( $one, $two, $three, $four, $five, $six ) = split; if ( $three eq "SOA" ) { $one =~ s/\.$//; $one =~ tr/a-z/A-Z/; print "\#\n\# DOMAIN $one\n"; $one =~ tr/A-Z/a-z/; $domain = $one; print "\#\n\# $domain server is $four\n"; $five =~ s/\./@/; print "\# and responsible person is $five\n\#\n"; $soa_found++; } if ( $one eq "\$ORIGIN" ) { $two =~ s/\.$//; $two =~ tr/A-Z/a-z/; $domain = $two; $origin++; } if ( $three eq "A" && $one ne "") { if ($one !~ m/\.$/ ) { # one of our machines, add alias if ( $one eq "localhost" && $origin ) { # do nothing } else { print "$four\t$one.$domain\t$one\n"; } } else { # not one of ours. Notate as such $one =~ s/\.$//; print "$four\t$one\t\t\# not one of ours\n"; } } } SHAR_EOF chmod +x 'makehosts' fi # end of overwriting check echo shar: extracting "'hosts.sample.input'" '(2686 characters)' if test -f 'hosts.sample.input' then echo shar: will not over-write existing file "'hosts.sample.input'" else cat << \SHAR_EOF > 'hosts.sample.input' # this is just a sample bind hosts file to demonstrate makehosts with cs.Miami.EDU. IN SOA mthvax.cs.Miami.EDU. aem.mthvax.cs.Miami.EDU. ( 901006 ; Serial 10800 ; Refresh 3600 ; Retry 3600000 ; Expire 86400 ) ; Minimum IN NS mthvax.cs.Miami.EDU. IN NS paris.cs.miami.edu. localhost IN A 127.0.0.1 mthvax IN A 129.171.32.5 IN MX 10 mthvax.cs.miami.edu. IN MX 20 paris.cs.miami.edu. IN MX 30 miavax.ir.miami.edu. IN HINFO VaxStation-II Ultrix-3.0 mthvax-cs IN A 192.31.89.3 IN MX 10 mthvax.cs.miami.edu. IN MX 20 paris.cs.miami.edu. IN MX 30 miavax.ir.miami.edu. IN HINFO VaxStation-II Ultrix-3.0 rio IN A 129.171.32.7 IN MX 10 rio.cs.miami.edu. IN MX 20 mthvax.cs.miami.edu. IN HINFO Sun-3/60 SunOS-4.1 ibiza IN A 192.31.89.1 IN MX 10 mthvax.cs.miami.edu. IN MX 20 rio.cs.miami.edu. IN HINFO Mac-II MacOS-6.0.5 mthnext IN A 192.31.89.10 IN HINFO NeXT Mach valencia IN A 129.171.34.6 IN MX 10 paris.cs.miami.edu. IN MX 50 mthvax.cs.miami.edu. IN HINFO Sun-4/20 SunOS-4.1c hibbing IN A 129.171.34.22 IN MX 10 paris.cs.miami.edu. IN MX 50 mthvax.cs.miami.edu. IN HINFO Sun-4/20 SunOS-4.1c anatolia IN A 129.171.34.8 IN MX 10 paris.cs.miami.edu. IN MX 20 mthvax.cs.miami.edu. IN MX 30 rio.cs.miami.edu. IN HINFO Sun-SPARCstation SunOS-4.1c paris IN A 129.171.32.9 IN MX 10 paris.cs.miami.edu. IN MX 20 mthvax.cs.miami.edu. IN HINFO Sun-4/370 SunOS-4.1c paris-gw IN A 192.70.171.1 IN MX 10 paris.cs.miami.edu. IN MX 20 mthvax.cs.miami.edu. izmir IN A 192.31.89.4 IN MX 10 mthvax.cs.miami.edu. IN HINFO Apple-Mac2 A/UX-1.1 nairobi IN A 192.31.89.6 IN MX 10 mthvax.cs.miami.edu. IN MX 20 rio.cs.miami.edu. IN HINFO Apple-Mac2 A/UX-1.1 boston IN A 192.31.89.8 IN MX 10 mthvax.cs.miami.edu. IN HINFO Apple-Mac2 MacOS-6.0.5 madrid IN A 192.70.171.2 IN MX 10 paris.cs.miami.edu. calella IN A 192.70.171.3 IN MX 10 paris.cs.miami.edu. la-jolla IN A 192.70.171.4 IN MX 10 paris.cs.miami.edu. oakland IN A 192.70.171.6 IN MX 10 paris.cs.miami.edu. IN MX 20 mthvax.cs.miami.edu. alanza IN A 192.70.171.7 IN MX 10 paris.cs.miami.edu. IN HINFO Mac-II MacOS-6.0.5 ankh.ftl.fl.us. IN MX 10 mthvax.cs.miami.edu. medex2.ftl.fl.us. IN MX 10 uunet.uu.net. medexam.ftl.fl.us. IN MX 10 uunet.uu.net. IN MX 50 mthvax.cs.miami.edu. love1.ftl.fl.us. IN MX 10 uunet.uu.net. IN MX 50 mthvax.cs.miami.edu. safe2.ftl.fl.us. IN MX 10 uunet.uu.net. IN MX 50 mthvax.cs.miami.edu. megasys.com. IN MX 10 mthvax.cs.miami.edu. metrolink.com. IN MX 10 mthvax.cs.miami.edu. SHAR_EOF fi # end of overwriting check echo shar: extracting "'hosts.sample.extra'" '(309 characters)' if test -f 'hosts.sample.extra' then echo shar: will not over-write existing file "'hosts.sample.extra'" else cat << \SHAR_EOF > 'hosts.sample.extra' # # extra hosts we keep in our hosts table, for historical reasons # 129.252.11.9 cs.scarolina.edu 130.73.72.1 ave.zib-berlin.de 130.113.1.1 maccs.dcss.mcmaster.ca 131.31.7.1 sm-logdis1-aflc.af.mil 131.170.8.11 minyos.xx.rmit.oz.au 131.211.32.41 fysaj.ruu.nl 192.48.96.2 uunet uunet.uu.net # # end of table # SHAR_EOF fi # end of overwriting check echo shar: extracting "'Makefile'" '(577 characters)' if test -f 'Makefile' then echo shar: will not over-write existing file "'Makefile'" else cat << \SHAR_EOF > 'Makefile' # # makefile for makehosts # # $Header: /tempf/aem/makehosts/RCS/Makefile,v 1.4 90/10/06 16:32:07 aem Exp $ # # BINDHOSTS should be the bind host tables to use as input # # EXTRAS should be any extra you want tacked on to the end of # the file # SHAR = README makehosts hosts.sample.input hosts.sample.extra Makefile BINDHOSTS = hosts.sample.input EXTRAS = hosts.sample.extra all: hosts hosts: ${BINDHOSTS} ${EXTRAS} makehosts @rm -f hosts makehosts ${BINDHOSTS} > hosts cat ${EXTRAS} >> hosts clean: rm -f hosts shar: ${SHAR} shar -v -b ${SHAR} > makehosts.shar SHAR_EOF fi # end of overwriting check # End of shell archive exit 0