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

75 lines
1.4 KiB
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"
TUN30_TEMP="$(mktemp)"
PP_TEMP="$(mktemp)"
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"
if [ "$TYPE" = "TUN30" ]; then
2020-04-27 13:58:16 +08:00
upstream_ip=$(ipcalc "$i" 1)
downstream_ip=$(ipcalc "$i" 2)
2020-04-26 11:10:48 +08:00
(
2020-04-26 12:20:06 +08:00
print_record "$upstream_ip" "$DOWNSTREAM.$UPSTREAM.tun30.neo."
print_record "$downstream_ip" "$UPSTREAM.$DOWNSTREAM.tun30.neo."
) >> "$TUN30_TEMP"
2020-04-28 22:32:36 +08:00
elif [ "$TYPE" = "PTP" ]; then
i="${i/PP,/}"
upstream_ip="${i%~*}"
downstream_ip="${i#*~}"
(
2020-04-27 13:58:16 +08:00
print_record "$(ipcalc "$upstream_ip" 0)" "$UPSTREAM.ptp.neo."
print_record "$(ipcalc "$downstream_ip" 0)" "$DOWNSTREAM.ptp.neo."
) >> "$PP_TEMP"
elif [ "$TYPE" = "LO" ]; then
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
)
{
echo -e "\n; Tunnel /30 Addresses"
sort -n < "$TUN30_TEMP"
echo -e "\n; Point to Point Addresses"
sort -n < "$PP_TEMP"
echo -e "\n; Loopback Addresses"
sort -n < "$LO_TEMP"
2020-04-28 22:32:36 +08:00
} >> "$FILE"
rm -f "$TUN30_TEMP" "$PP_TEMP" "$LO_TEMP"