刘小帅

域名Gfw屏蔽、google浏览器安全、域名过期天数
import requests import re import colorama from colorama i...
扫描右侧二维码阅读全文
27
2020/06

域名Gfw屏蔽、google浏览器安全、域名过期天数

import requests
import re
import colorama
from colorama import init,Fore,Back,Style
init(autoreset=True)
import time
from time import sleep
import datetime
from threading import Thread
#author anan
#所取域名文本是win10桌面的domain.txt 需要生成结果文件请自行调整
#检测域名过期 google浏览器屏蔽 被墙 
class GoogleCheck(object):

    def __init__(self,url,agent,name):
        self._url = url
        self._agent = agent
        self._name = name
    
    @property
    
    def agent(self):
        return self._agent
    
    @property
    def name(self):
        return self._name

    def googlecheck(self):
        result = requests.get(self._url,self._agent)
        try:
            if result.status_code == 200:
                result1 = result.text
                check = re.findall('2,0,0(.*)',result1)
                sleep(0.5)
                if check:
                    print('\033[31m{}被google封掉了\033[0m'.format(self._name))
                else:
                    print('\033[32m{}没有被google封掉\033[0m'.format(self._name))

        except requests.RequestException as e:
            return None

class Gfwcheck(object):
    
    def __init__(self,url,header,data,name):
        self._url = url
        self._header = header
        self._data = data
        self._name = name
    
    @property
    def header(self):
        return self._header
    
    def data(self):
        return self._data
    
    def name(self):
        return self._name

    def gfwcheck(self):
        resp = requests.post(self._url,headers=self._header,data=self._data)
        if resp.status_code == 200:
            resp =resp.text
            cre = re.compile('恭喜.*。')
            anan = re.findall(cre,resp)
            sleep(0.5)
            if anan:
                print(self._name,'\033[32m未被墙\033[0m')
            else:
                print(self._name,'\033[31m被墙\033[0m')

class Ssldatecheck(object):

    def __init__(self,url,agent,name):
        self._url = url
        self._agent = agent
        self._name = name
    
    @property
    def url(self):
        return self._url
    
    @property
    def agent(self):
        return self._agent

    @property
    def name(self):
        return self._name
    
    def check(self):
        result = requests.get(self._url,headers=self._agent,allow_redirects=False)
        try:
            if result.status_code == 200:
                result = result.text
                sleep(0.5)
                result = re.findall(r'Expiry Date: \d{1,4}-\d{1,2}-\d{1,2}',result)
                result1 = re.findall(r'\d{1,4}-\d{1,2}-\d{1,2}',result[0])[0]
                result2 = datetime.date.today()
                start_sec = time.mktime(time.strptime(result1,'%Y-%m-%d'))
                end_sec = time.mktime(time.strptime(str(result2),'%Y-%m-%d'))
                work_days = int((start_sec - end_sec)/(24*60*60))
                print(self._name,'还有{}天过期'.format(work_days))

        except requests.RequestException as e:
            return None



def google():
    #google安全查询
    with open(r'C:\Users\Administrator\Desktop\domain.txt','r',encoding='utf-8') as e:
        for i in e:
            i = i.strip('\n')
            header = {
                'User-Agent':'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/83.0.4103.116 Safari/537.36'
            }
            url = 'https://transparencyreport.google.com/transparencyreport-tr/api/v3/safebrowsing/status?site={}'.format(i)
            anan = GoogleCheck(url,header,i)
            anan.googlecheck()

def gfw():
    # 被墙查询
    checkurl = 'https://www.checkgfw.com/service.cgi/check'
    headers = {
        'Uset-Agent':'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/83.0.4103.116 Safari/537.36',
        'x_post_with': 'fcm-ajax',
        'cookie':'__cfduid=ddc0515f5a5ee3b19e61196f5548fbe541593171904; Hm_lvt_ed21fa9f306580c67ba65dad794a6a03=1593171905; Hm_lpvt_ed21fa9f306580c67ba65dad794a6a03=1593171905; __tins__15100225=%7B%22sid%22%3A%201593171905400%2C%20%22vd%22%3A%201%2C%20%22expires%22%3A%201593173705400%7D; __51cke__=; __51laig__=1',
        'content-type': 'application/x-www-form-urlencoded; charset=UTF-8',
        'referer': 'https://www.checkgfw.com/',
    }

    with open(r'C:\Users\Administrator\Desktop\domain.txt','r',encoding='utf-8') as e:
        for i in e:
            i = i.strip('\n')
            data = {'func': 'true','m': 'check','a': 'check','domain':i,'captcha':'(empty)(empty)','x_post_with': 'fcm-ajax'}
            anan = Gfwcheck(checkurl,headers,data,i)
            anan.gfwcheck()

def domaindateck():
    #域名过期天数查询
    header = {
        'User-Agent':'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/83.0.4103.116 Safari/537.36',
        'Cookie':'__cfduid=d04fa6dc4b546916f2bddace5d8e89f021593333489; PHPSESSID=5fbb296f196998fa05d5fa093095f4fc; Hm_lvt_3f1150f340cc3312f4c632e8879e1dbf=1593333492; Hm_lpvt_3f1150f340cc3312f4c632e8879e1dbf=1593341384'
    }
    with open(r'C:\Users\Administrator\Desktop\domain.txt','r',encoding='utf-8') as e:
        for i in e:
            i = i.strip('\n')
            url = 'https://whois.ac/{}'.format(i)
            anan = Ssldatecheck(url,header,i)
            anan.check()

def main():
    checktype = input("请输入你要查询类型,同时查询多个请用逗号分隔!\n1代表google安全查询 2代表被墙查询 3代表域名过期时间查询\n请输入:")
    if checktype == '1':
        google()
    elif checktype == '2':
        gfw()
    elif checktype == '3':
        domaindateck()
    elif '1' in checktype and '2' in checktype and '3' in checktype:
        a1 = Thread(target=google,args='',)
        a1.start()
        a2 = Thread(target=gfw,args='',)
        a2.start()
        a3 = Thread(target=domaindateck,args='',)
        a3.start()
        a1.join()
        a2.join()
        a3.join()
    else:
        print('输入错误请重新输入')


if __name__ == "__main__":
    main()
from abc import ABCMeta,abstractmethod
import requests
import re
import colorama
from colorama import init,Fore,Back,Style
init(autoreset=True)
import time
from time import sleep
import datetime
from threading import Thread
import os

#author anan
#所取域名文本是win10桌面的domain.txt  结果文件都在桌面 googlefailed.txt google屏蔽的域名  gfw.txt被墙域名 domaindate.txt 小于十天过期的域名

#检测域名过期 google浏览器屏蔽 被墙 

class Checkurl(metaclass=ABCMeta):

    def __init__(self,name):
        self.name = name
    
    def checkgoogle(self):
        pass

    def checkdomaindate(self):
        pass

    def checkgfw(self):
        pass

class Google(Checkurl):
    
    def __init__(self,url,agent,name):
        super().__init__(name)
        self.url = url
        self.agent = agent
    
    def checkgoogle(self):
        resp = requests.get(self.url,headers=self.agent)
        try:
            if resp.status_code == 200:
                resp1 = resp.text
                sleep(0.5)
                result = re.findall('2,0,0(.*)',resp1)
                if result:
                    print('\033[31m{}被google封掉了\033[0m\n'.format(self.name))
                    with open(r'C:\Users\Administrator\Desktop\googlefailed.txt','a+',encoding='utf-8') as e:
                        e.write('{}google屏蔽了\n'.format(self.name))
                else:
                    print('\033[32m{}没有被google封掉\033[0m\n'.format(self.name))
        except requests.RequestException as e:
            return None

class Checkdomaindate(Checkurl):
    
    def __init__(self,url,agent,name):
        self.url = url
        self.agent = agent
        super().__init__(name)
    
    def checkdomaindate(self):
        resp = requests.get(self.url,headers=self.agent,allow_redirects=False)
        try:
            if resp.status_code == 200:
                result = resp.text
                sleep(0.5)
                try:
                    result = re.findall(r'Expiry Date: \d{1,4}-\d{1,2}-\d{1,2}',result)
                    result1 = re.findall(r'\d{1,4}-\d{1,2}-\d{1,2}',result[0])[0]
                    result2 = datetime.date.today()
                    start_sec = time.mktime(time.strptime(result1,'%Y-%m-%d'))
                    end_sec = time.mktime(time.strptime(str(result2),'%Y-%m-%d'))
                    work_days = int((start_sec - end_sec)/(24*60*60))
                    print(self.name,'还有{}天过期\n'.format(work_days))
                    if work_days < 10:
                        with open(r'C:\Users\Administrator\Desktop\domaindate.txt','a+',encoding='utf-8') as e:
                            e.write('{}还有{}天过期\n'.format(self.name,work_days))
                except:
                    with open(r'C:\Users\Administrator\Desktop\domaindate.txt','a+',encoding='utf-8') as e:
                        e.write('{}域名后缀不常见,在whis.ac查询不到 请手动去其他网站查询\n'.format(self.name))
        except requests.RequestException as e:
            return None

class Checkgfw(Checkurl):

    def __init__(self,url,agent,data,name):
        super().__init__(name)
        self.url = url
        self.agent = agent
        self.data = data
    
    def checkgfw(self):
        resp = requests.post(self.url,headers=self.agent,data=self.data)
        try:
            if resp.status_code == 200:
                resp =resp.text
                cre = re.compile('很不幸.*')
                anan = re.findall(cre,resp)
                if anan:
                    print(self.name,'\033[31m被墙\033[0m\n')
                    with open(r'C:\Users\Administrator\Desktop\gfw.txt','a+',encoding='utf-8') as e:
                        e.write('{}被墙\n'.format(self.name))                    
                else:
                    print(self.name,'\033[32m未被墙\033[0m\n')
                sleep(1)
        except requests.RequestException as e:
            return None

class EmployeeFactory:
    
    @staticmethod
    def create(emp_type,*args,**kwargs):
        all_emp_types = {'G': Google,'D': Checkdomaindate,'W':Checkgfw}
        cls = all_emp_types[emp_type.upper()]
        return cls(*args,**kwargs) if cls else None


def rungoogle():
    with open(r'C:\Users\Administrator\Desktop\domain.txt','r',encoding='utf-8') as i:
        for name in i:
            name = name.strip('\n')
            url = 'https://transparencyreport.google.com/transparencyreport-tr/api/v3/safebrowsing/status?site={}'.format(name)
            header = {
                'User-Agent':'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/83.0.4103.116 Safari/537.36'
            }
            emps = [
                EmployeeFactory.create('G',url,header,name)
            ]
            for emp in emps:
                emp.checkgoogle()

def runcheckdomaindate():
    with open(r'C:\Users\Administrator\Desktop\domain.txt','r',encoding='utf-8') as i:
        for name in i:
            name = name.strip('\n')
            url = 'https://whois.ac/{}'.format(name)
            header = {
                'User-Agent':'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/83.0.4103.116 Safari/537.36',
                'Cookie':'__cfduid=d04fa6dc4b546916f2bddace5d8e89f021593333489; PHPSESSID=5fbb296f196998fa05d5fa093095f4fc; Hm_lvt_3f1150f340cc3312f4c632e8879e1dbf=1593333492; Hm_lpvt_3f1150f340cc3312f4c632e8879e1dbf=1593341384'
            }
            emps = [
                EmployeeFactory.create('D',url,header,name)
            ]
            for emp in emps:
                emp.checkdomaindate()

def runcheckgfw():
    with open(r'C:\Users\Administrator\Desktop\domain.txt','r',encoding='utf-8') as i:
        for name in i:
            name = name.strip('\n')
            url = 'https://www.checkgfw.com/service.cgi/check'
            header = {
                'Uset-Agent':'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/83.0.4103.116 Safari/537.36',
                'x_post_with': 'fcm-ajax',
                'cookie':'__cfduid=ddc0515f5a5ee3b19e61196f5548fbe541593171904; Hm_lvt_ed21fa9f306580c67ba65dad794a6a03=1593171905; Hm_lpvt_ed21fa9f306580c67ba65dad794a6a03=1593171905; __tins__15100225=%7B%22sid%22%3A%201593171905400%2C%20%22vd%22%3A%201%2C%20%22expires%22%3A%201593173705400%7D; __51cke__=; __51laig__=1',
                'content-type': 'application/x-www-form-urlencoded; charset=UTF-8',
                'referer': 'https://www.checkgfw.com/',
            }
            data = {'func': 'true','m': 'check','a': 'check','domain':name,'captcha':'(empty)(empty)','x_post_with': 'fcm-ajax'}
            emps = [
                EmployeeFactory.create('W',url,header,data,name)
            ]
            for emp in emps:
                emp.checkgfw()

def fileinfo(filename):
    if os.path.exists(filename) == True:
        os.remove(filename)

def main():
    fileinfo(filename=r'C:\Users\Administrator\Desktop\domaindate.txt')
    fileinfo(filename=r'C:\Users\Administrator\Desktop\googlefailed.txt')
    fileinfo(filename=r'C:\Users\Administrator\Desktop\gfw.txt')
    t1 = Thread(target=runcheckdomaindate,args='',)
    t1.start()
    t2 = Thread(target=rungoogle,args='',)
    t2.start()
    t3 = Thread(target=runcheckgfw,args='',)
    t3.start()
    t1.join()
    t2.join()
    t3.join()

if __name__ == "__main__":
    main()
Last modification:June 29th, 2020 at 07:25 pm
If you think my article is useful to you, please feel free to appreciate

Leave a Comment