1
0
Fork 0
mirror of https://github.com/NeoCloud/NeoNetwork synced 2024-11-25 22:00:41 +08:00
NeoNetwork/scripts/dns-reverse-generator.sh
2020-05-11 17:33:01 +08:00

62 lines
1 KiB
Bash
Executable file

#!/usr/bin/env bash
set -e
FILE="dns/db.10.127"
TUN30_TEMP="$(mktemp)"
LO_TEMP="$(mktemp)"
if [[ "$(uname)" = *BSD ]]; then
TAC=gtac
else
TAC=tac
fi
print_record()
{
printf "%s\tIN\tPTR\t%s\n" "$1" "$2"
}
ipcalc()
{
local subnet="$1"
local add="$2"
REV="$(echo -n "${subnet%,*}." | "$TAC" -s .)"
REV="${REV%.*.*.}"
echo "$[ ${REV%.*} + $add ].${REV#*.}"
}
# PROGRAM BEGIN
sed -i '/AUTOGENERATED/,$d' "$FILE"
echo '; AUTOGENERATED' >> "$FILE"
(
cd route
for i in *; do
source "$i"
if [ "$TYPE" = "TUN30" ]; then
upstream_ip=$(ipcalc "$i" 1)
downstream_ip=$(ipcalc "$i" 2)
(
print_record "$upstream_ip" "$DOWNSTREAM.$UPSTREAM.tun30.neo."
print_record "$downstream_ip" "$UPSTREAM.$DOWNSTREAM.tun30.neo."
) >> "$TUN30_TEMP"
elif [ "$TYPE" = "LO" ]; then
ip="${i/,32/}"
print_record "$(ipcalc "$ip" 0)" "$NAME.neo" >> "$LO_TEMP"
fi
done
)
{
echo -e "\n; Tunnel /30 Addresses"
sort -n < "$TUN30_TEMP"
echo -e "\n; Loopback Addresses"
sort -n < "$LO_TEMP"
} >> "$FILE"
rm -f "$TUN30_TEMP" "$LO_TEMP"