1
0
Fork 0
mirror of https://github.com/NeoCloud/NeoNetwork synced 2024-11-16 11:50:40 +08:00
NeoNetwork/scripts/dns-reverse-generator.sh

52 lines
685 B
Bash
Raw Normal View History

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"
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
ip="${i/,32/}"
2020-05-14 17:33:05 +08:00
print_record "$(ipcalc "$ip" 0)" "$NAME.neo." >> "$LO_TEMP"
2020-04-26 11:10:48 +08:00
fi
done
)
{
echo -e "\n; Loopback Addresses"
sort -n < "$LO_TEMP"
2020-04-28 22:32:36 +08:00
} >> "$FILE"
2020-05-12 21:20:53 +08:00
rm -f "$LO_TEMP"