-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.py
More file actions
84 lines (70 loc) · 2.42 KB
/
Copy pathapp.py
File metadata and controls
84 lines (70 loc) · 2.42 KB
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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
import json
import requests
import hashlib
from flask import Flask, render_template, request
app = Flask(__name__)
JSON_URL = "https://www.microsoft.com/en-us/download/confirmation.aspx?id=56519"
JSON_PATH = "/path/to/json/file.json"
HASH_PATH = "/path/to/hash/file.txt"
IP_TABLE = []
WHOIS_API_KEY = "your-api-key"
WHOIS_API_URL = "https://example.com/whois?ip="
def download_json():
response = requests.get(JSON_URL)
data = response.content
with open(JSON_PATH, "wb") as file:
file.write(data)
def load_json():
with open(JSON_PATH, "r") as file:
return json.load(file)
def save_hash(hash_value):
with open(HASH_PATH, "w") as file:
file.write(hash_value)
def load_hash():
try:
with open(HASH_PATH, "r") as file:
return file.read().strip()
except FileNotFoundError:
return None
def compute_hash():
with open(JSON_PATH, "rb") as file:
content = file.read()
return hashlib.md5(content).hexdigest()
def update_data():
hash_value = compute_hash()
if hash_value != load_hash():
download_json()
save_hash(hash_value)
# Compute data from the updated JSON and update IP_TABLE
def search_ip(ip_address):
# Implement IP search logic using CIDR calculations and IP_TABLE
pass
def query_whois(ip_address):
url = WHOIS_API_URL + ip_address
headers = {"Authorization": f"Bearer {WHOIS_API_KEY}"}
response = requests.get(url, headers=headers)
if response.status_code == 200:
data = response.json()
return {
"ip_address": data.get("ip_address"),
"resolve_host": data.get("resolve_host"),
"whois_server": data.get("whois_server"),
"organization": data.get("organization"),
}
return None
@app.route("/cidrapp/list")
def list_ip_addresses():
update_data()
return render_template("list.html", ip_table=IP_TABLE)
@app.route("/cidrapp/search", methods=["GET", "POST"])
def search():
if request.method == "POST":
ip_address = request.form.get("ip_address")
result = search_ip(ip_address)
if not result:
whois_data = query_whois(ip_address)
return render_template("not_found.html", ip_address=ip_address, whois_data=whois_data)
return render_template("search.html", ip_address=ip_address, result=result)
return render_template("search.html")
if __name__ == "__main__":
app.run()