Skip to content

Instantly share code, notes, and snippets.

@cnDelbert
Created December 26, 2015 15:54
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cnDelbert/58de67f236351de3134c to your computer and use it in GitHub Desktop.
Save cnDelbert/58de67f236351de3134c to your computer and use it in GitHub Desktop.
Get domains which would expire in 2 days and match the keyword you interested in.
# -*- coding: utf-8 -*-
__author__ = 'Delbert'
import requests
def init():
domainList = list()
future0ListURL = 'http://www.cnnic.cn/download/registar_list/1todayDel.txt'
future1ListURL = 'http://www.cnnic.cn/download/registar_list/future1todayDel.txt'
future2ListURL = 'http://www.cnnic.cn/download/registar_list/future2todayDel.txt'
urlList = [future0ListURL, future1ListURL, future2ListURL]
for i in range(len(urlList)):
domainList.append(requestDomainList(urlList[i]))
return domainList
def requestDomainList(url, requestCnt=3):
requestCount = requestCnt
resp = requests.get(url)
if resp.status_code == 200:
domains = resp.text.split('\n')
print("请求域名列表成功 " + domains[0][2:-2])
elif requestCount > 0:
print("请求列表失败,正在重新请求")
requestDomainList(url, requestCount-1)
else:
print("请求域名列表失败")
exit('-1')
return domains[1:]
def searchDomainList(domainList, kw, day):
cnt = 0
matchList = list()
for domain in domainList:
if kw in domain[:-3]:
cnt += 1
matchList.append(domain)
if day == 0:
print("###今天的搜索结果是:", end=" ")
elif day ==1:
print("###明天的搜索结果是:", end=" ")
elif day ==2:
print("###后天的搜索结果是:", end=" ")
if cnt == 0:
print("Oops...没有匹配到域名")
else:
print("匹配到{n}个域名:".format(n=cnt))
for domain in matchList:
print(domain.strip('[]'))
return str(cnt)
def main():
domainList = init()
expireDay = int(input("Expire Time of .CN Domains\n"
"(0 for today;\t\t\t\t\t 1 for tomorrow;\n"
" 2 for the day after tomorrow;\t"
" 3 for all)\t:"))
keyword = input("Your keyword:")
while(keyword != "EXIT"):
cnt = list()
if expireDay == 3:
for i in range(len(domainList)):
cnt.append(searchDomainList(domainList[i], keyword, i))
else:
cnt.append(searchDomainList(domainList[expireDay], keyword, expireDay))
print("### Matched count: {i}".format(i=' '.join(cnt)))
keyword = input("Another keyword or EXIT to exit:")
if __name__ == '__main__':
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment