2020-04-26 11:10:48 +08:00
|
|
|
#!/usr/bin/env bash
|
|
|
|
set -e
|
|
|
|
|
2020-04-28 22:32:36 +08:00
|
|
|
FILE="dns/db.10.127"
|
2020-04-26 19:49:55 +08:00
|
|
|
LO_TEMP="$(mktemp)"
|
|
|
|
|
2020-04-27 13:58:16 +08:00
|
|
|
if [[ "$(uname)" = *BSD ]]; then
|
|
|
|
TAC=gtac
|
|
|
|
else
|
|
|
|
TAC=tac
|
2020-04-26 11:10:48 +08:00
|
|
|
fi
|
|
|
|
|
|
|
|
print_record()
|
|
|
|
{
|
|
|
|
printf "%s\tIN\tPTR\t%s\n" "$1" "$2"
|
|
|
|
}
|
|
|
|
|
2020-04-27 13:58:16 +08:00
|
|
|
ipcalc()
|
|
|
|
{
|
|
|
|
local subnet="$1"
|
|
|
|
local add="$2"
|
|
|
|
|
|
|
|
REV="$(echo -n "${subnet%,*}." | "$TAC" -s .)"
|
|
|
|
REV="${REV%.*.*.}"
|
|
|
|
|
|
|
|
echo "$[ ${REV%.*} + $add ].${REV#*.}"
|
|
|
|
}
|
|
|
|
|
|
|
|
# PROGRAM BEGIN
|
|
|
|
|
2020-04-28 22:32:36 +08:00
|
|
|
sed -i '/AUTOGENERATED/,$d' "$FILE"
|
|
|
|
echo '; AUTOGENERATED' >> "$FILE"
|
2020-04-26 11:10:48 +08:00
|
|
|
|
|
|
|
(
|
|
|
|
cd route
|
|
|
|
for i in *; do
|
|
|
|
source "$i"
|
2020-05-12 21:20:53 +08:00
|
|
|
if [ "$TYPE" = "LO" ]; then
|
2020-04-26 19:49:55 +08:00
|
|
|
ip="${i/,32/}"
|
|
|
|
|
2020-04-27 13:58:16 +08:00
|
|
|
print_record "$(ipcalc "$ip" 0)" "$NAME.neo" >> "$LO_TEMP"
|
2020-04-26 11:10:48 +08:00
|
|
|
fi
|
|
|
|
done
|
2020-04-26 19:49:55 +08:00
|
|
|
)
|
|
|
|
|
|
|
|
{
|
|
|
|
echo -e "\n; Loopback Addresses"
|
|
|
|
sort -n < "$LO_TEMP"
|
2020-04-28 22:32:36 +08:00
|
|
|
} >> "$FILE"
|
2020-04-26 19:49:55 +08:00
|
|
|
|
2020-05-12 21:20:53 +08:00
|
|
|
rm -f "$LO_TEMP"
|