File size: 1,205 Bytes
2e0beca
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import json
import whois
from fastapi import FastAPI, Request
from fastapi.responses import HTMLResponse
from fastapi.templating import Jinja2Templates

app = FastAPI()
templates = Jinja2Templates(directory="templates")


def find_related_domains(domain):
    related_domains = []
    # 対象のドメインのWHOISレコードを取得
    w = whois.whois(domain)
    # 所有者情報を取得
    owner = w.get('owner')
    # 同じ所有者情報を持つドメインを検索
    if owner:
        for w in whois.query('domain ' + domain):
            if w.get('owner') == owner:
                related_domains.append(w.domain)
    return related_domains


@app.get("/")
def read_root(request: Request):
    return templates.TemplateResponse("index.html", {"request": request})


@app.get("/api/find-related-domains")
def find_related_domains_api(domain: str):
    related_domains = find_related_domains(domain)
    return {"related_domains": related_domains}


@app.get("/find-related-domains")
def find_related_domains_web(domain: str):
    related_domains = find_related_domains(domain)
    return templates.TemplateResponse("index.html", {"related_domains": related_domains, "domain": domain})