Yasu777's picture
Create app.py
2e0beca
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})