forked from ring04h/wydomain
-
Notifications
You must be signed in to change notification settings - Fork 1
/
domain_aizhan_all.py
157 lines (146 loc) · 4.97 KB
/
domain_aizhan_all.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
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
#! /usr/bin/env python
#-*- coding: utf-8 -*-
import urllib2
import sys
import re
import HTMLParser
import socket
import cookielib
import math
import json
from StringIO import StringIO
import gzip
import signal
import time
reload(sys)
sys.setdefaultencoding('utf-8')
domains = {}
cj = cookielib.LWPCookieJar()
cookie_support = urllib2.HTTPCookieProcessor(cj)
opener = urllib2.build_opener(cookie_support, urllib2.HTTPHandler)
urllib2.install_opener(opener)
class TimeOutException(Exception):
pass
def timeout(seconds, *args, **kwargs):
def fn(f):
def wrapped_fn(*args, **kwargs):
signal.signal(signal.SIGALRM, handler)
signal.alarm(seconds)
f(*args, **kwargs)
return wrapped_fn
return fn
def handler(signum, frame):
pass
# raise TimeOutException("Timeout")
# http://dns.aizhan.com/index.php?r=index/getress&q=59.32.181.65&page=1
def getHtml(ip,page):
trytime = 0
while True:
try:
request = urllib2.Request("http://dns.aizhan.com/?q="+ ip +"&page="+ str(page) )
request.add_header('User-Agent', 'Mozilla/5.0 (Windows NT 6.1; WOW64; rv:21.0) Gecko/20100101 Firefox/21.0')
request.add_header('Accept-encoding', 'gzip')
request.add_header('X-FORWARDED-FOR', ip)
request.add_header('Referer', request.get_full_url())
u = urllib2.urlopen(request , timeout = 30)
content = ''
if u.info().get('Content-Encoding') == 'gzip':
buf = StringIO(u.read())
f = gzip.GzipFile(fileobj=buf)
content = f.read()
else:
content = u.read()
type = sys.getfilesystemencoding()
return content.decode("UTF-8").encode(type)
except:
trytime+=1
if trytime>3:
return ""
def getDomains(ip,page):
global domains
trytime = 0
while True:
try:
request = urllib2.Request("http://dns.aizhan.com/index.php?r=index/domains&ip="+ ip +"&page="+ str(page) )
request.add_header('User-Agent', 'Mozilla/5.0 (Windows NT 6.1; WOW64; rv:21.0) Gecko/20100101 Firefox/21.0')
request.add_header('Accept-encoding', 'gzip')
request.add_header('X-FORWARDED-FOR', ip)
request.add_header('Referer', request.get_full_url())
u = urllib2.urlopen(request , timeout = 30)
content = ''
if u.info().get('Content-Encoding') == 'gzip':
buf = StringIO(u.read())
f = gzip.GzipFile(fileobj=buf)
content = f.read()
else:
content = u.read()
type = sys.getfilesystemencoding()
content = content.decode("UTF-8").encode(type)
domaintemp = json.loads(content,encoding="utf-8")
for d in domaintemp["domains"]:
try:
proto, rest = urllib2.splittype("http://"+ str(d))
host, rest = urllib2.splithost(rest)
host, port = urllib2.splitport(host)
if port == None:
port = 80
if not domains.has_key(host):
domains[host] = port
except:
pass
return
except:
trytime+=1
if trytime>0:
return
def getIp(domain):
trytime = 0
while True:
try:
myaddr = socket.getaddrinfo(domain,'http')[0][4][0]
return myaddr
except:
trytime+=1
if trytime>3:
return ""
@timeout(10)
def getHtmlByUrl(url):
global domains
try:
u = urllib2.urlopen(url,timeout = 10.0)
content = u.read()
if content !="":
try:
proto, rest = urllib2.splittype(url)
host, rest = urllib2.splithost(rest)
host, port = urllib2.splitport(host)
domains[host] = int(port)
except:
pass
return content
except:
pass
def reverse_aizhan(arges):
ipandport = arges
try :
info = getHtmlByUrl("http://"+ ipandport)
except:
pass
ip = ipandport.split(':')[0]
info = getHtml(ip,1)
if info!="":
match =re.search(r'<font color="#FF0000" id="yhide">(\d*)</font>',info)
if match:
count = int(match.group(1))
count = int(math.ceil(count / 20.0))
for i in range(count):
getDomains(ip,(i+1))
# print (json.dumps(domains,encoding="utf-8"))
return (json.dumps(domains,encoding="utf-8"))
if __name__ == "__main__":
if len(sys.argv) == 2:
print reverse_aizhan(sys.argv[1])
sys.exit(0)
else:
print ("usage: %s ip" % sys.argv[0])
sys.exit(-1)