Yasu777 commited on
Commit
2e0beca
•
1 Parent(s): f1a5dbf

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +39 -0
app.py ADDED
@@ -0,0 +1,39 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import json
2
+ import whois
3
+ from fastapi import FastAPI, Request
4
+ from fastapi.responses import HTMLResponse
5
+ from fastapi.templating import Jinja2Templates
6
+
7
+ app = FastAPI()
8
+ templates = Jinja2Templates(directory="templates")
9
+
10
+
11
+ def find_related_domains(domain):
12
+ related_domains = []
13
+ # 対象のドメインのWHOISレコードを取得
14
+ w = whois.whois(domain)
15
+ # 所有者情報を取得
16
+ owner = w.get('owner')
17
+ # 同じ所有者情報を持つドメインを検索
18
+ if owner:
19
+ for w in whois.query('domain ' + domain):
20
+ if w.get('owner') == owner:
21
+ related_domains.append(w.domain)
22
+ return related_domains
23
+
24
+
25
+ @app.get("/")
26
+ def read_root(request: Request):
27
+ return templates.TemplateResponse("index.html", {"request": request})
28
+
29
+
30
+ @app.get("/api/find-related-domains")
31
+ def find_related_domains_api(domain: str):
32
+ related_domains = find_related_domains(domain)
33
+ return {"related_domains": related_domains}
34
+
35
+
36
+ @app.get("/find-related-domains")
37
+ def find_related_domains_web(domain: str):
38
+ related_domains = find_related_domains(domain)
39
+ return templates.TemplateResponse("index.html", {"related_domains": related_domains, "domain": domain})