| 1 |
from __future__ import print_function |
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
import sys |
| 10 |
sys.path.append('..') |
| 11 |
|
| 12 |
import IPy |
| 13 |
|
| 14 |
|
| 15 |
ns = {'ns.nerxs.com': '213.221.113.70', |
| 16 |
'ns.dorsch.org': '195.143.234.25', |
| 17 |
'ns.c0re.jp': '217.6.214.130'} |
| 18 |
|
| 19 |
print("# *** nameservers ***") |
| 20 |
for x in ns: |
| 21 |
print("=%s:%s" % (x, ns[x])) |
| 22 |
|
| 23 |
print("\n# *** domains ***") |
| 24 |
|
| 25 |
fd = open('domains') |
| 26 |
|
| 27 |
for x in fd.readlines(): |
| 28 |
if x[0] != '#': |
| 29 |
if x[-1] == '\n': |
| 30 |
x = x[:-1] |
| 31 |
(domain, owner) = x.split(':') |
| 32 |
print("'%s:Contact for this domain is %s" % (domain, owner)) |
| 33 |
for y in ns: |
| 34 |
print(".%s::%s" % (domain, y)) |
| 35 |
|
| 36 |
fd.close() |
| 37 |
|
| 38 |
print("\n# *** Networks ***") |
| 39 |
|
| 40 |
fd = open('networks') |
| 41 |
ip6map = {} |
| 42 |
rmap = {} |
| 43 |
nmap = {} |
| 44 |
|
| 45 |
for x in fd.readlines(): |
| 46 |
if x[-1] == '\n': |
| 47 |
x = x[:-1] |
| 48 |
if len(x) > 0 and x[0] != '#': |
| 49 |
nets = x.split(',') |
| 50 |
name = nets.pop(0) |
| 51 |
print("# Network: %s" % name) |
| 52 |
for y in nets: |
| 53 |
ip = IPy.IP(y) |
| 54 |
print("# Address range: %s (%s), %d addresses" % (ip.strCompressed(), ip.iptype(), ip.len())) |
| 55 |
print("=net.%s:%s" % (name, ip.net())) |
| 56 |
print("=broadcast.%s:%s" % (name, ip.broadcast())) |
| 57 |
|
| 58 |
if ip.version() == 4: |
| 59 |
for z in ip: |
| 60 |
|
| 61 |
nmap[z.int()] = name |
| 62 |
rmap[z.int()] = z.strBin() + "." + name |
| 63 |
else: |
| 64 |
|
| 65 |
for z in ns: |
| 66 |
for v in ip.reverseName(): |
| 67 |
print(".%s::%s" % (v, z)) |
| 68 |
ip6map[ip.strFullsize(0)] = name |
| 69 |
|
| 70 |
fd.close() |
| 71 |
|
| 72 |
print("\n# *** hosts ***") |
| 73 |
|
| 74 |
fd = open('hosts') |
| 75 |
|
| 76 |
for x in fd.readlines(): |
| 77 |
if x[-1] == '\n': |
| 78 |
x = x[:-1] |
| 79 |
if x != '' and x[0] != '#': |
| 80 |
if "@Z'.".find(x[0]) >= 0: |
| 81 |
print(x) |
| 82 |
else: |
| 83 |
if "=+'".find(x[0]) >= 0: |
| 84 |
i = x.split(':') |
| 85 |
rmap[IPy.IP(i[1]).int()] = '' |
| 86 |
print(x) |
| 87 |
else: |
| 88 |
x = x[1:] |
| 89 |
x += '||||' |
| 90 |
fields = x.split('|') |
| 91 |
name = fields.pop(0) |
| 92 |
if name[0] == '.': |
| 93 |
name = name[1:] |
| 94 |
v = fields.pop(0) |
| 95 |
ips = v.split(',') |
| 96 |
v = fields.pop(0) |
| 97 |
aliases = v.split(',') |
| 98 |
if aliases == ['']: |
| 99 |
aliases = [] |
| 100 |
admin = fields.pop() |
| 101 |
if admin == '': |
| 102 |
admin = '[email protected]' |
| 103 |
v = fields.pop() |
| 104 |
mxes = v.split(',') |
| 105 |
if mxes == ['']: |
| 106 |
mxes = [] |
| 107 |
for y in ips: |
| 108 |
ip = IPy.IP(y) |
| 109 |
if ip.version() == 4: |
| 110 |
|
| 111 |
if ip.int() not in nmap: |
| 112 |
print("*** warning: no network for %s (%s) - ignoring" % (y, name), file=sys.stderr) |
| 113 |
print("# no network for %s (%s)" % (y, name)) |
| 114 |
else: |
| 115 |
print("=%s.%s:%s" % (name, nmap[ip.int()], y)) |
| 116 |
print("'%s.%s:Host contact is %s" % (name, nmap[ip.int()], admin)) |
| 117 |
rmap[ip.int()] = '' |
| 118 |
for z in aliases: |
| 119 |
print("+%s:%s" % (z, ip)) |
| 120 |
print("'%s:Host contact is %s" % (z, admin)) |
| 121 |
else: |
| 122 |
|
| 123 |
net = ip.strFullsize(0) |
| 124 |
net = net[:19] + ':0000:0000:0000:0000' |
| 125 |
if net in ip6map: |
| 126 |
print("*** warning: no network for %s (%s) - ignoring" % (ip, name), file=sys.stderr) |
| 127 |
print("# no network for %s (%s) - ignoring" % (ip, name)) |
| 128 |
else: |
| 129 |
print("6%s.%s:%s" % (name, ip6map[net], ip.strHex()[2:])) |
| 130 |
for z in aliases: |
| 131 |
print("3%s:%s" % (name, ip.strHex()[2:])) |
| 132 |
print("'%s:Host contact is %s" % (name, admin)) |
| 133 |
|
| 134 |
fd.close() |
| 135 |
|
| 136 |
print("\n# *** reverse lookup ***") |
| 137 |
for x in sorted(nmap): |
| 138 |
if rmap.get(x): |
| 139 |
print("=%s:%s" % (rmap[x], str(IPy.IP(x)))) |
| 140 |
|