This repository has been archived by the owner on Nov 25, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
generate-hrefs.py
executable file
·111 lines (84 loc) · 3.57 KB
/
generate-hrefs.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
#!/usr/bin/env python2
import config
import json
import re
import socket
import httplib
import base64
import string
import sys
# this script has been quickly hacked together from the source of
# generate-maradns-config.py. you probably don't want to use it (in it's
# current form).
def get_json(server, user, passwd):
params = {'version': 1.1, 'method': 'name_scan', 'params': ['', 21474836487], 'id': 1}
auth = 'Basic ' + string.strip(base64.encodestring(user + ':' + passwd))
headers = {"Content-type": "application/json", "Authorization": auth}
conn = httplib.HTTPConnection(server)
conn.request("POST", "/", json.dumps(params), headers)
response = conn.getresponse()
if response.status == 200:
data = response.read()
return data
return None
def isValidHostElem(hostname):
allowed = re.compile("(?!-)[a-z\d-]{1,63}(?<!-)$")
return allowed.match(hostname)
def isValidHostname(hostname):
if len(hostname) > 255:
return False
if hostname[-1:] == ".":
hostname = hostname[:-1]
allowed = re.compile("(?!-)[a-z\d-]{1,63}(?<!-)$")
return all(allowed.match(x) for x in hostname.split("."))
data = get_json(config.SERVER, config.USER, config.PASSWD)
if data is None:
sys.exit(1)
data = json.loads(data)['result']
# print "% NS bitname0.sysfrog.org. ~"
# print "% NS bitname1.sysfrog.org. ~"
# print "% A 178.63.239.23 ~"
print """<html>
<head><title>list of direct bitname.org mappings</title></head>
<body>"""
for item in data:
name = item['name']
if name.startswith('d/'):
name = name[2:]
if isValidHostElem(name) and item.get('expires_in', -1) >= 0:
try:
payload = json.loads(item['value'])
if type(payload) == dict and payload.has_key('map'):
mapping = payload['map']
if mapping.has_key(''):
root = mapping['']
if type(root) == type({}) and root.has_key('ns'):
ns = root['ns']
if type(ns) == type([]):
for server in ns:
if isValidHostname(server):
if not server.endswith('.'):
server = server + '.'
# print "%s.%% NS %s ~" % (name, server)
continue
elif type(root) == type('') or type(root) == type(u''):
try:
ip = socket.inet_ntoa(socket.inet_aton(root))
# print "%s.%% A %s ~" % (name, ip)
# print "*.%s.%% A %s ~" % (name, ip)
print '<a href="http://%s.bitname.org/">%s.bitname.org</a><br />' % (name, name)
except socket.error:
pass
for key in mapping.keys():
if key == '':
continue
root = mapping[key]
if (type(root) == type('') or type(root) == type(u'')) and isValidHostElem(key):
try:
ip = socket.inet_ntoa(socket.inet_aton(root))
# print "%s.%s.%% A %s ~" % (key, name, ip)
except socket.error:
pass
except ValueError:
pass
print "</body></html>"