From abcf4ed1379838a0448a2cfcaa04611d856f1548 Mon Sep 17 00:00:00 2001 From: Blackwhitebear8 Date: Sun, 12 Jan 2025 17:20:16 +0100 Subject: [PATCH] Add arp.py --- arp.py | 168 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 168 insertions(+) create mode 100644 arp.py diff --git a/arp.py b/arp.py new file mode 100644 index 0000000..9cd951e --- /dev/null +++ b/arp.py @@ -0,0 +1,168 @@ +import json +import subprocess +from jinja2 import Template +from flask import Flask, render_template_string, jsonify + +app = Flask(__name__) + +# Functie om de cURL-oproep te doen voor de ARP-tabel +def run_curl_command(): + curl_command = [ + "curl", "-k", "--location", "--request", "POST", "https://ip:port/show", + "--form", "data={\"op\": \"show\", \"path\": [\"arp\"]}", + "--form", "key=key" + ] + response = subprocess.check_output(curl_command, text=True) + return json.loads(response) + +# Functie om de ARP-gegevens te verwerken +def parse_arp_data(data): + arp_table = [] + + if "data" in data: + raw_data = data["data"] + + # Verwerk de gegevens per regel + for line in raw_data.split("\n"): + if line.strip() and not line.startswith("Address"): + arp_info = line.split() + if len(arp_info) >= 4: + arp_table.append({ + "address": arp_info[0], + "interface": arp_info[1], + "link_layer_address": arp_info[2], + "state": arp_info[3] + }) + + return arp_table + +# Functie om de ARP-tabel in HTML te genereren +def generate_html_table(arp_table): + html_template = """ + + + + + + ARP Table + + + + + +
+

Core1.Doet.pixelHosting.nl ARP Table

+ + + + + + + + + + + + + {% for entry in arp_table %} + + + + + + + {% endfor %} + +
AddressInterfaceLink Layer AddressState
{{ entry.address }}{{ entry.interface }}{{ entry.link_layer_address }}{{ entry.state }}
+
+ + + + + + + + + + """ + + template = Template(html_template) + html_output = template.render(arp_table=arp_table) + + return html_output + +# Route om de ARP-tabel weer te geven als HTML +@app.route('/') +def arp_table_summary(): + data = run_curl_command() + + arp_table = parse_arp_data(data) + + html_output = generate_html_table(arp_table) + + return render_template_string(html_output) + +# Route om de ARP-tabel als JSON weer te geven +@app.route('/json') +def arp_table_summary_json(): + data = run_curl_command() + + arp_table = parse_arp_data(data) + + json_data = { + "arp_table": arp_table + } + + return jsonify(json_data) + +if __name__ == '__main__': + app.run(host='0.0.0.0', port=5000, debug=True)