4
4
import sys
5
5
import array
6
6
7
+ import msvcrt
8
+
9
+ from utils .proxyManager import ProxyManager
7
10
from utils .utils import *
8
11
from multiprocessing .dummy import Pool as ThreadPool
9
12
10
- DOMAIN_NAMES_FILE = "DomainNamesFile.txt"
11
- DomainCheckResult = "DomainCheckResult.txt"
12
-
13
+ man = ProxyManager ()
14
+ class config :
15
+ MAX_THREAD_COUNT = 30
16
+ FailedRetryTimes = 20
17
+ DomainNamesList = "DomainNamesList.txt"
18
+ resultFilename = "DomainCheck_result.txt"
13
19
14
- def checkDomain (name ):
20
+ def checkWithBaiduWhois (name ):
21
+ #http://whois.bj.baidubce.com/whois?format=javascript&domain=whatthesdfksdjf.com
22
+ domainName = name + ".com"
23
+ url = r"http://whois.bj.baidubce.com/whois?format=javascript&domain=" + domainName
24
+ # url=r"https://checkapi.aliyun.com/check/checkdomain?callback=result&domain=azzzz.shop&token=check-web-hichina-com%3A7s88yvbgwterj87mk5llo6k6owagkw4u"
25
+ return GetUrlContent2 (url ,proxies = man .popProxies ())
26
+ def checkWithBaiduApi (name ):
27
+ # https://cloud.baidu.com/api/bcd/search/status
28
+ # {"domainNames":[{"label":"sz","tld":"com"}]}
29
+ domainName = name
30
+ url = r"https://cloud.baidu.com/api/bcd/search/status"
31
+
32
+ header = {
33
+ 'Connection' : 'keep-alive' ,
34
+ 'Content-Length' : '44' ,
35
+ 'Pragma' : 'no-cache' ,
36
+ 'Cache-Control' : 'no-cache' ,
37
+ 'Accept' : 'application/json, text/javascript, */*; q=0.01' ,
38
+ 'Origin' : 'https://cloud.baidu.com' ,
39
+ 'X-Requested-With' : 'XMLHttpRequest' ,
40
+ 'User-Agent' : 'Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/62.0.3202.94 Safari/537.36' ,
41
+ 'Content-Type' : 'application/json' ,
42
+ 'Referer' : 'https://cloud.baidu.com/product/bcd/search.html?keyword=sz' ,
43
+ 'Accept-Encoding' : 'gzip, deflate, br' ,
44
+ 'Accept-Language' : 'zh-CN,zh;q=0.9,en-US;q=0.8,en;q=0.7' ,
45
+ 'Cookie' : 'BAIDUID=ABDF12D91049CBD5AA0895DAFCA1144D:FG=1; PSTM=1491968808; BIDUPSID=D0C77823B4F11112E550D605C212D8D9; BDUSS=DVpUlk5eUZnWmdkM09WUHE3VmJQNVhCekY2bE9Wd0tRNmFBMnpCR3RKQ202d3RhTVFBQUFBJCQAAAAAAAAAAAEAAADG3h0rY29kZXJsaW4AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAKZe5FmmXuRZW; MCITY=-340%3A; BCLID=10955523308864486684; BDSFRCVID=5G_sJeC62Ra1LkRAhCCwhM3RN2K2PtoTH6aopK_Jf9Dcn3ODE-HlEG0PJU8g0KubVI2-ogKK3gOTH4nP; H_BDCLCKID_SF=tbAjVIPaf-3bfTrTKb55-P_3qxby26nfMmJeaJ5nJD_BSl6q5TJNqJ8Vjf7uJbkjWgcXKqTOQpP-HqTYLp3b2h-ghJoKah5eKjREKl0MLPbYbb0xyn_VKP_bDfnMBMPe52OnaIb8LIF-MK8xejK2en-W5gT0tC62aKDX3buQJlIMqpcNLTDK2Mty2R393CrWBmr32COytn5ZjnTIylO1j4_e3bjw54vmWmO0bRIEtfTbJh5jDh3Ub6ksD-Rte4on-6Ry0hvctb3cShPmhl00Djb-jN0qJ6FsKKJ03bk8KRREJt5kq4bohjn0QnneBtQmJJrN3Cj12MoNjhOJ5P7YDpDND44HQn3yQg-q3R7MWM7keCTe-PI5XU0kqt7Q0x-jLgQPVn0MW-5DSlI4qtnJyUnybPnnBT3XLnQ2QJ8BJDtKMCQP; PSINO=6; H_PS_PSSID=25245_1423_13289_21097_20697_25439_25178_20719; CAMPAIGN_TRACK=cp%3Aaladdin%7Ckw%3A139; CAMPAIGN_TRACK_TIME=2017-12-23+18%3A15%3A11; Hm_lvt_28a17f66627d87f1d046eae152a1c93d=1513070462,1514024132; Hm_lpvt_28a17f66627d87f1d046eae152a1c93d=1514024141' ,
46
+ }
47
+ data = "{\" domainNames\" :[{\" label\" :\" " + domainName + "\" ,\" tld\" :\" com\" }]}"
48
+ return PostUrlWithDataAndHeader (url , data , header )
49
+
50
+
51
+ def checkWithAliyunApi (name ):
15
52
domainName = name + ".com"
16
- reprint ("checking " + domainName + " ..." )
17
53
url = r"https://checkapi.aliyun.com/check/checkdomain?callback=result&domain=" + domainName + r"&token=check-web-hichina-com%3A7s88yvbgwterj87mk5llo6k6owagkw4u"
18
54
# url=r"https://checkapi.aliyun.com/check/checkdomain?callback=result&domain=azzzz.shop&token=check-web-hichina-com%3A7s88yvbgwterj87mk5llo6k6owagkw4u"
19
- response = GetUrlContent2 (url )
20
- appendStrToFile (response + "\n " , DomainCheckResult )
55
+ return GetUrlContent2 (url )
56
+
57
+
58
+ def checkDomain (name ):
59
+ reprint ("checking " + name + " ..." )
60
+ retryCount = 0
61
+ while True :
62
+ try :
63
+ # response= checkWithAliyunApi(name)
64
+ # response = checkWithBaiduApi(name)
65
+ response = checkWithBaiduWhois (name )
66
+ if "\" status\" :0" in response :
67
+ break ;
68
+ except BaseException as e :
69
+ pass
70
+ retryCount += 1
71
+ if retryCount > config .FailedRetryTimes :
72
+ response = "Failed:" + e .message
73
+ break
74
+ reprint ("checking %s ... retry #%d" % (name ,retryCount ))
75
+ loglToFile ("%s\t %d\t --->\t " % (name , retryCount ) + response , config .resultFilename )
21
76
# logl(response)
22
77
return "ok"
23
78
@@ -38,8 +93,8 @@ def strPlusOne(t):
38
93
39
94
40
95
def BuildDomainList (fileName ):
41
- startName = 'aaaaa '
42
- endName = 'zzzzz '
96
+ startName = 'aa '
97
+ endName = 'zz '
43
98
# nameList = []
44
99
logl ("Building name list:%s to %s..." % (startName , endName ))
45
100
while startName != endName :
@@ -61,17 +116,42 @@ def LoadDomainList(fileName):
61
116
62
117
63
118
def CheckAllDomains (nameList ):
64
- pool = ThreadPool ()
119
+ pool = ThreadPool (config .MAX_THREAD_COUNT )
120
+ logl (pool ._processes )
65
121
pool .map (checkDomain , nameList )
66
122
pool .close ()
67
123
pool .join ()
68
124
logl ('All done.' )
69
125
70
126
127
+ def usage ():
128
+ logl ("usage:%s DOMAIN_NAMES_FILE" )
129
+
130
+
131
+ def raise_test ():
132
+ raise BaseException ("test" )
133
+
134
+
135
+ def test ():
136
+ try :
137
+ raise_test ()
138
+ except BaseException as a :
139
+ logl ("Exception:" + a .message )
140
+
141
+
71
142
def main ():
72
- logl ("Loading domain names from %s .." % DOMAIN_NAMES_FILE )
73
- nameList = LoadDomainList (DOMAIN_NAMES_FILE )
74
- logl ("%d names loaded." % len (nameList ))
143
+ # test()
144
+ # return
145
+ logl ("test end." )
146
+ if len (sys .argv ) == 2 :
147
+ config .DomainNamesListFile = sys .argv [1 ]
148
+ config .resultFilename = "result_" + config .DomainNamesListFile
149
+ else :
150
+ usage ()
151
+ return
152
+ logl ("Loading domain names from %s .." % config .DomainNamesListFile )
153
+ nameList = LoadDomainList (config .DomainNamesListFile )
154
+ logl ("%d names loaded." % len (nameList ))
75
155
logl ("Checking..." )
76
156
CheckAllDomains (nameList )
77
157
logl ("All done." )
@@ -80,4 +160,6 @@ def main():
80
160
if __name__ == '__main__' :
81
161
# BuildDomainList(DOMAIN_NAMES_FILE)
82
162
main ()
83
- # checkDomain("aaaaa")
163
+ logl ("<<" )
164
+ msvcrt .getch ()
165
+ # checkDomain("as")
0 commit comments