80 lines
2.1 KiB
Python
80 lines
2.1 KiB
Python
# -*- coding: UTF-8 -*-
|
|
'''
|
|
@Project :domainScanDemo
|
|
@File :google_detector.py
|
|
@IDE :PyCharm
|
|
@Author :梦伴
|
|
@Date :2026/4/9 0:00
|
|
@explain : Google检测器
|
|
'''
|
|
|
|
import requests
|
|
from curl_cffi import requests as curl_requests
|
|
import re
|
|
from app.detectors.base import BaseDetector
|
|
|
|
|
|
class GoogleDetector(BaseDetector):
|
|
"""
|
|
Google检测器
|
|
"""
|
|
|
|
def __init__(self):
|
|
"""
|
|
初始化Google检测器
|
|
"""
|
|
super().__init__()
|
|
self.site_url = 'https://www.google.com/search'
|
|
|
|
def check_domain(self, domain):
|
|
"""
|
|
检测域名
|
|
|
|
:param domain: 域名
|
|
:return: dict - 检测结果
|
|
"""
|
|
try:
|
|
# 检查Google site
|
|
site_result = self.check_site(domain)
|
|
|
|
return {
|
|
'site': site_result
|
|
}
|
|
except Exception as e:
|
|
return self._handle_exception(e, domain)
|
|
|
|
def check_site(self, domain):
|
|
"""
|
|
检查Google site收录
|
|
|
|
:param domain: 域名
|
|
:return: dict - 检测结果
|
|
"""
|
|
try:
|
|
params = {
|
|
'q': f'site:{domain}',
|
|
'num': '50'
|
|
}
|
|
|
|
headers = {
|
|
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/146.0.0.0 Safari/537.36'
|
|
}
|
|
|
|
# 使用curl_cffi模拟浏览器
|
|
response = curl_requests.get(self.site_url, params=params, headers=headers, impersonate='chrome', timeout=10)
|
|
|
|
if response.status_code == 200:
|
|
content = response.text
|
|
|
|
# 检查是否有收录
|
|
has_收录 = 'No results found for' not in content
|
|
|
|
return {
|
|
'has_收录': has_收录
|
|
}
|
|
else:
|
|
self._log_warning(f"Google site查询失败: {response.status_code}")
|
|
return {'error': f'HTTP {response.status_code}'}
|
|
except Exception as e:
|
|
return self._handle_exception(e, domain)
|