#!/bin/bash # # nslookup ls -> /etc/hosts # Psychoskylark of LiE (psylark@nol.net) # July 11, 1995 # usage : nsl2hosts.sh # e.g. nsl2hosts /tmp/usis.ls usis.com #---------------------------------------------------------- hostend=${2} lsfile=${1} tmp1=/tmp/b00.$$ tmp2=/tmp/bew.$$ tmp3=/tmp/518.$$ hold1=/tmp/hold.1.$$ hold2=/tmp/hold.2.$$ hold3=/tmp/hold.3.$$ hold4=/tmp/hold.4.$$ ofile=./hosts.out if [ "${#}" != "2" ] then echo " nsl2hosts by psychoskylark of LiE (psylark@nol.net). Read the GPL for CopyLeft information. Usage - ${0} where is the file created by nslookup and is the ending of the hostname (e.g. nol.net) example: ${0} nol.ls .nol.net will produce ${ofile} in /etc/hosts form " exit 0 fi if [ -r ${lsfile} ] then echo "Cleaning NSLOOKUP's Stuff Out Of The File" grep -vi "${hostend}" ${lsfile} > ${tmp1} ; grep -vi "server =" ${tmp1} > ${tmp2} rm ${tmp1} cat ${tmp2} > ${hold1} echo "Formatting File, This May Take A While If The File Is Large " rm ${tmp2} echo "s/ / @/2" > ${tmp2} sed -f ${tmp2} ${hold1} > ${tmp3} rm ${tmp2} cat ${tmp3} | cut -f1 -d@ -s > ${tmp2} rm ${tmp3} sed 's/ /@/2' ${tmp2} > ${tmp3} rm ${tmp2} echo "s/@/.${hostend}/g" > ${tmp1} sed -f ${tmp1} ${tmp3} > ${tmp2} rm ${tmp1} ; rm ${tmp3} cut -f1 -d. -s ${tmp2} > ${hold2} cat ${tmp2} > ${hold3} rm ${tmp2} echo "s/ /@/2" > ${tmp1} sed -f ${tmp1} ${hold1} > ${tmp2} rm ${tmp1} ; rm ${hold1} echo "y/abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ/xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx/" > ${tmp1} sed -f ${tmp1} ${tmp2} > ${tmp3} rm ${tmp1} ; rm ${tmp2} cut -f2 -d@ -s ${tmp3} > ${tmp2} rm ${tmp3} echo "s/ //g" > ${tmp1} sed -f ${tmp1} ${tmp2} > ${tmp3} rm ${tmp2} ; rm ${tmp1} paste ${tmp3} ${hold3} > ${tmp2} ; paste -d " " ${tmp2} ${hold2} > ${tmp1} rm ${tmp3} ; rm ${hold2} ; rm ${tmp2} ; rm ${hold3} echo "#/etc/hosts created by nsl2hosts 0.1 by psychoskylark of LiE " > ${tmp2} cat ${tmp1} >> ${tmp2} mv ${tmp2} ${ofile} rm ${tmp1} echo "Done. File Created : ${ofile} " exit 0 fi exit 0