1
0
Fork 0
mirror of https://github.com/NeoCloud/NeoNetwork synced 2024-12-25 13:09:23 +08:00

DNS: generator: ip calculation in bash

This commit is contained in:
Neo_Chen 2020-04-27 13:58:16 +08:00
parent 91eff9f3ae
commit 9dce524994
2 changed files with 40 additions and 26 deletions

View file

@ -107,22 +107,24 @@ $TTL 604800
142.0 IN PTR pan.icecat-jp3.tun30.neo.
; Point to Point Addresses
1.10 IN PTR LanTian.pp.neo.
1.69 IN PTR santost12.pp.neo.
2.127 IN PTR dfceaef.pp.neo.
99.51 IN PTR JerryXiao.pp.neo.
185.8 IN PTR staph.pp.neo.
193.8 IN PTR JerryXiao.pp.neo.
193.8 IN PTR JerryXiao.pp.neo.
193.8 IN PTR JerryXiao.pp.neo.
194.8 IN PTR JerryXiao-HK1.pp.neo.
194.8 IN PTR JerryXiao-HK1.pp.neo.
194.8 IN PTR JerryXiao-HK1.pp.neo.
195.8 IN PTR JerryXiao-SH1.pp.neo.
195.8 IN PTR JerryXiao-SH1.pp.neo.
196.8 IN PTR JerryXiao-HK2.pp.neo.
199.11 IN PTR SUNNET.pp.neo.
254.4 IN PTR Icecat-Explosion.pp.neo.
1.10 IN PTR LanTian.ptp.neo.
1.69 IN PTR santost12.ptp.neo.
1.69 IN PTR santost12.ptp.neo.
2.127 IN PTR dfceaef.ptp.neo.
99.51 IN PTR JerryXiao.ptp.neo.
185.8 IN PTR staph.ptp.neo.
193.8 IN PTR JerryXiao.ptp.neo.
193.8 IN PTR JerryXiao.ptp.neo.
193.8 IN PTR JerryXiao.ptp.neo.
194.8 IN PTR JerryXiao-HK1.ptp.neo.
194.8 IN PTR JerryXiao-HK1.ptp.neo.
194.8 IN PTR JerryXiao-HK1.ptp.neo.
195.8 IN PTR JerryXiao-SH1.ptp.neo.
195.8 IN PTR JerryXiao-SH1.ptp.neo.
196.8 IN PTR JerryXiao-HK2.ptp.neo.
199.11 IN PTR SUNNET.ptp.neo.
253.4 IN PTR MagicNeko-JP3.ptp.neo.
254.4 IN PTR Icecat-Explosion.ptp.neo.
; Loopback Addresses
1.255 IN PTR NeoPDP-11.neo

View file

@ -1,15 +1,14 @@
#!/usr/bin/env bash
set -e
IPTOOL="$PWD/Misc/C/ip"
TUN30_TEMP="$(mktemp)"
PP_TEMP="$(mktemp)"
LO_TEMP="$(mktemp)"
if [ ! -x "$IPTOOL" ]; then
echo "You need to build Misc/C/ip first"
exit 1
if [[ "$(uname)" = *BSD ]]; then
TAC=gtac
else
TAC=tac
fi
print_record()
@ -17,6 +16,19 @@ 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' dns/db.10.127
echo '; AUTOGENERATED' >> dns/db.10.127
@ -25,8 +37,8 @@ cd route
for i in *; do
source "$i"
if [ "$TYPE" = "TUN30" ]; then
upstream_ip=$("$IPTOOL" "$i" 1)
downstream_ip=$("$IPTOOL" "$i" 2)
upstream_ip=$(ipcalc "$i" 1)
downstream_ip=$(ipcalc "$i" 2)
(
print_record "$upstream_ip" "$DOWNSTREAM.$UPSTREAM.tun30.neo."
@ -38,13 +50,13 @@ for i in *; do
downstream_ip="${i#*~}"
(
print_record "$("$IPTOOL" "$upstream_ip" 0)" "$UPSTREAM.ptp.neo."
print_record "$("$IPTOOL" "$downstream_ip" 0)" "$DOWNSTREAM.ptp.neo."
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/}"
print_record "$("$IPTOOL" "$ip" 0)" "$NAME.neo" >> "$LO_TEMP"
print_record "$(ipcalc "$ip" 0)" "$NAME.neo" >> "$LO_TEMP"
fi
done
)