mirror of
https://github.com/NeoCloud/NeoNetwork
synced 2024-11-22 12:40:40 +08:00
rfc2317 script
This commit is contained in:
parent
61224360eb
commit
47cfb85f58
4 changed files with 226 additions and 102 deletions
117
dns/db.10.127
117
dns/db.10.127
|
@ -36,6 +36,99 @@ $TTL 604800
|
|||
2.8 IN PTR blog.librehs.neo.
|
||||
|
||||
; DELEGATED ZONES
|
||||
9 IN NS ns1.jerry.neo.
|
||||
|
||||
12 IN NS ns1.yangfl.dn42.
|
||||
NS ns2.yangfl.dn42.
|
||||
|
||||
10 IN NS ns1.lantian.neo.
|
||||
10 IN NS ns2.lantian.neo.
|
||||
10 IN NS ns3.lantian.neo.
|
||||
10 IN NS ns4.lantian.neo.
|
||||
10 IN NS ns5.lantian.neo.
|
||||
|
||||
7 IN NS ns1.staph.neo.
|
||||
|
||||
|
||||
; DO NOT MANUALLY EDIT THE FOLLOWING LINES
|
||||
; AUTOGENERATED
|
||||
|
||||
; Loopback Addresses
|
||||
1.255 IN PTR NeoPDP-11.neo.
|
||||
2.255 IN PTR ucbvax.neo.
|
||||
4.255 IN PTR pan.neo.
|
||||
53.255 IN PTR JerryXiao-Anycast4.neo.
|
||||
56.255 IN PTR frank-hsinchu-1.neo.
|
||||
80.255 IN PTR NeoSystem.neo.
|
||||
117.255 IN PTR magicneko-tw.neo.
|
||||
|
||||
; rfc2317
|
||||
64/26.8 IN NS ns1.jerry.neo.
|
||||
64.8 IN CNAME 64.64/26.8
|
||||
65.8 IN CNAME 65.64/26.8
|
||||
66.8 IN CNAME 66.64/26.8
|
||||
67.8 IN CNAME 67.64/26.8
|
||||
68.8 IN CNAME 68.64/26.8
|
||||
69.8 IN CNAME 69.64/26.8
|
||||
70.8 IN CNAME 70.64/26.8
|
||||
71.8 IN CNAME 71.64/26.8
|
||||
72.8 IN CNAME 72.64/26.8
|
||||
73.8 IN CNAME 73.64/26.8
|
||||
74.8 IN CNAME 74.64/26.8
|
||||
75.8 IN CNAME 75.64/26.8
|
||||
76.8 IN CNAME 76.64/26.8
|
||||
77.8 IN CNAME 77.64/26.8
|
||||
78.8 IN CNAME 78.64/26.8
|
||||
79.8 IN CNAME 79.64/26.8
|
||||
80.8 IN CNAME 80.64/26.8
|
||||
81.8 IN CNAME 81.64/26.8
|
||||
82.8 IN CNAME 82.64/26.8
|
||||
83.8 IN CNAME 83.64/26.8
|
||||
84.8 IN CNAME 84.64/26.8
|
||||
85.8 IN CNAME 85.64/26.8
|
||||
86.8 IN CNAME 86.64/26.8
|
||||
87.8 IN CNAME 87.64/26.8
|
||||
88.8 IN CNAME 88.64/26.8
|
||||
89.8 IN CNAME 89.64/26.8
|
||||
90.8 IN CNAME 90.64/26.8
|
||||
91.8 IN CNAME 91.64/26.8
|
||||
92.8 IN CNAME 92.64/26.8
|
||||
93.8 IN CNAME 93.64/26.8
|
||||
94.8 IN CNAME 94.64/26.8
|
||||
95.8 IN CNAME 95.64/26.8
|
||||
96.8 IN CNAME 96.64/26.8
|
||||
97.8 IN CNAME 97.64/26.8
|
||||
98.8 IN CNAME 98.64/26.8
|
||||
99.8 IN CNAME 99.64/26.8
|
||||
100.8 IN CNAME 100.64/26.8
|
||||
101.8 IN CNAME 101.64/26.8
|
||||
102.8 IN CNAME 102.64/26.8
|
||||
103.8 IN CNAME 103.64/26.8
|
||||
104.8 IN CNAME 104.64/26.8
|
||||
105.8 IN CNAME 105.64/26.8
|
||||
106.8 IN CNAME 106.64/26.8
|
||||
107.8 IN CNAME 107.64/26.8
|
||||
108.8 IN CNAME 108.64/26.8
|
||||
109.8 IN CNAME 109.64/26.8
|
||||
110.8 IN CNAME 110.64/26.8
|
||||
111.8 IN CNAME 111.64/26.8
|
||||
112.8 IN CNAME 112.64/26.8
|
||||
113.8 IN CNAME 113.64/26.8
|
||||
114.8 IN CNAME 114.64/26.8
|
||||
115.8 IN CNAME 115.64/26.8
|
||||
116.8 IN CNAME 116.64/26.8
|
||||
117.8 IN CNAME 117.64/26.8
|
||||
118.8 IN CNAME 118.64/26.8
|
||||
119.8 IN CNAME 119.64/26.8
|
||||
120.8 IN CNAME 120.64/26.8
|
||||
121.8 IN CNAME 121.64/26.8
|
||||
122.8 IN CNAME 122.64/26.8
|
||||
123.8 IN CNAME 123.64/26.8
|
||||
124.8 IN CNAME 124.64/26.8
|
||||
125.8 IN CNAME 125.64/26.8
|
||||
126.8 IN CNAME 126.64/26.8
|
||||
127.8 IN CNAME 127.64/26.8
|
||||
|
||||
192/26.8 IN NS ns1.jerry.neo.
|
||||
192.8 IN CNAME 192.192/26.8
|
||||
193.8 IN CNAME 193.192/26.8
|
||||
|
@ -101,18 +194,7 @@ $TTL 604800
|
|||
253.8 IN CNAME 253.192/26.8
|
||||
254.8 IN CNAME 254.192/26.8
|
||||
255.8 IN CNAME 255.192/26.8
|
||||
9 IN NS ns1.jerry.neo.
|
||||
|
||||
12 IN NS ns1.yangfl.dn42.
|
||||
NS ns2.yangfl.dn42.
|
||||
|
||||
10 IN NS ns1.lantian.neo.
|
||||
10 IN NS ns2.lantian.neo.
|
||||
10 IN NS ns3.lantian.neo.
|
||||
10 IN NS ns4.lantian.neo.
|
||||
10 IN NS ns5.lantian.neo.
|
||||
|
||||
7 IN NS ns1.staph.neo.
|
||||
160/27.8 IN NS ns1.staph.neo.
|
||||
160.8 IN CNAME 160.160/27.8
|
||||
161.8 IN CNAME 161.160/27.8
|
||||
|
@ -146,16 +228,3 @@ $TTL 604800
|
|||
189.8 IN CNAME 189.160/27.8
|
||||
190.8 IN CNAME 190.160/27.8
|
||||
191.8 IN CNAME 191.160/27.8
|
||||
|
||||
; DO NOT MANUALLY EDIT THE FOLLOWING LINES
|
||||
; AUTOGENERATED
|
||||
|
||||
; Loopback Addresses
|
||||
3.89 IN PTR chenx97-conoha.neo.
|
||||
1.255 IN PTR NeoPDP-11.neo.
|
||||
2.255 IN PTR ucbvax.neo.
|
||||
4.255 IN PTR pan.neo.
|
||||
53.255 IN PTR JerryXiao-Anycast.neo.
|
||||
56.255 IN PTR frank-hsinchu-1.neo.
|
||||
80.255 IN PTR NeoSystem.neo.
|
||||
117.255 IN PTR magicneko-tw.neo.
|
||||
|
|
8
dns/rfc2317.toml
Normal file
8
dns/rfc2317.toml
Normal file
|
@ -0,0 +1,8 @@
|
|||
["10.127.8.64/26"]
|
||||
ns = ["ns1.jerry.neo."]
|
||||
|
||||
["10.127.8.192/26"]
|
||||
ns = ["ns1.jerry.neo."]
|
||||
|
||||
["10.127.8.160/27"]
|
||||
ns = ["ns1.staph.neo."]
|
|
@ -4,10 +4,11 @@ from ipaddress import IPv4Address, ip_network, IPv4Network
|
|||
from pathlib import Path
|
||||
|
||||
import toml
|
||||
from rfc2317 import gen_reverse_pointers
|
||||
|
||||
RESOLVE_FILE = Path("dns", "db.10.127")
|
||||
ROUTE_FILE = Path("route")
|
||||
|
||||
RFC2317_FILE = Path("dns", "rfc2317.toml")
|
||||
|
||||
def iter_route(route_type: str):
|
||||
items = []
|
||||
|
@ -18,8 +19,22 @@ def iter_route(route_type: str):
|
|||
for route, entity in routes.items()
|
||||
if entity["type"] == route_type and isinstance(ip_network(route), IPv4Network)
|
||||
)
|
||||
routes = []
|
||||
remove = []
|
||||
for item in items[::-1]:
|
||||
if item[1] in routes:
|
||||
remove.append(item)
|
||||
else:
|
||||
routes.append(item[1])
|
||||
for i in remove:
|
||||
items.remove(i)
|
||||
return sorted(items, key=lambda item: item[1])
|
||||
|
||||
def iter_rfc2317_entry():
|
||||
entries = toml.loads(RFC2317_FILE.read_text())
|
||||
for (route, attributes) in entries.items():
|
||||
ns = attributes.get('ns')
|
||||
yield(route, ns)
|
||||
|
||||
def main():
|
||||
orignal = RESOLVE_FILE.read_text()
|
||||
|
@ -29,7 +44,13 @@ def main():
|
|||
if isinstance(address, IPv4Address):
|
||||
pointer = address.reverse_pointer.replace(".127.10.in-addr.arpa", "")
|
||||
records.append("%s\tIN\tPTR\t%s.neo." % (pointer, name))
|
||||
RESOLVE_FILE.write_text("\n".join(records)+"\n")
|
||||
|
||||
records.extend(("", "; rfc2317"))
|
||||
for route, ns in iter_rfc2317_entry():
|
||||
records.extend(gen_reverse_pointers(route, ns))
|
||||
records.append("")
|
||||
|
||||
RESOLVE_FILE.write_text("\n".join(records))
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
|
|
26
scripts/rfc2317.py
Executable file
26
scripts/rfc2317.py
Executable file
|
@ -0,0 +1,26 @@
|
|||
#!/usr/bin/env python3
|
||||
|
||||
import ipaddress
|
||||
|
||||
ZONE = '.127.10.in-addr.arpa'
|
||||
def truncate(rev: str) -> str:
|
||||
assert rev.endswith(ZONE)
|
||||
rev = rev[:-len(ZONE)]
|
||||
return rev
|
||||
|
||||
def gen_reverse_pointers(network: str, ns: list) -> list:
|
||||
buf = list()
|
||||
net = ipaddress.IPv4Network(network, strict=True)
|
||||
assert net.prefixlen > 24
|
||||
netrev = truncate(net.reverse_pointer)
|
||||
for _ns in ns:
|
||||
buf.append(f"{netrev:<10s} IN NS {_ns}")
|
||||
|
||||
for addr in net:
|
||||
cnamefr = truncate(addr.reverse_pointer)
|
||||
cnameto = f"{int.from_bytes(addr.packed, byteorder='big', signed=False) & 0xff}.{netrev}"
|
||||
buf.append(f"{cnamefr:<10s} IN CNAME {cnameto}")
|
||||
return buf
|
||||
|
||||
if __name__ == "__main__":
|
||||
print("\n".join(gen_reverse_pointers('10.127.8.64/26', ['ns1.jerry.neo.'])))
|
Loading…
Reference in a new issue