1
0
Fork 0
mirror of https://github.com/NeoCloud/NeoNetwork synced 2024-11-29 23:20:41 +08:00
NeoNetwork/scripts/rfc2317.py

27 lines
799 B
Python
Raw Normal View History

2020-09-23 14:41:36 +08:00
#!/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.'])))