Delete arp.py
This commit is contained in:
parent
38bfa7c133
commit
48f98504b3
1 changed files with 0 additions and 162 deletions
162
arp.py
162
arp.py
|
|
@ -1,162 +0,0 @@
|
||||||
import json
|
|
||||||
import subprocess
|
|
||||||
from jinja2 import Template
|
|
||||||
from flask import Flask, render_template_string, jsonify
|
|
||||||
|
|
||||||
app = Flask(__name__)
|
|
||||||
|
|
||||||
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)
|
|
||||||
|
|
||||||
def parse_arp_data(data):
|
|
||||||
arp_table = []
|
|
||||||
|
|
||||||
if "data" in data:
|
|
||||||
raw_data = data["data"]
|
|
||||||
|
|
||||||
for line in raw_data.split("\n"):
|
|
||||||
if line.strip() and not line.startswith("Address") and "---" not in line:
|
|
||||||
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
|
|
||||||
|
|
||||||
def generate_html_table(arp_table):
|
|
||||||
html_template = """
|
|
||||||
<!DOCTYPE html>
|
|
||||||
<html lang="en">
|
|
||||||
<head>
|
|
||||||
<meta charset="UTF-8">
|
|
||||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
||||||
<title>ARP Table</title>
|
|
||||||
<!-- Materialize CSS -->
|
|
||||||
<link href="https://cdnjs.cloudflare.com/ajax/libs/materialize/1.0.0/css/materialize.min.css" rel="stylesheet">
|
|
||||||
<style>
|
|
||||||
.container {
|
|
||||||
margin-top: 30px;
|
|
||||||
}
|
|
||||||
table {
|
|
||||||
border-collapse: collapse;
|
|
||||||
width: 100%;
|
|
||||||
}
|
|
||||||
th, td {
|
|
||||||
border: 1px solid #ddd;
|
|
||||||
padding: 8px;
|
|
||||||
text-align: left;
|
|
||||||
}
|
|
||||||
th {
|
|
||||||
background-color: #f4f4f4;
|
|
||||||
}
|
|
||||||
footer {
|
|
||||||
height: 50px;
|
|
||||||
background-color: #f4f4f4;
|
|
||||||
margin-top: 30px;
|
|
||||||
}
|
|
||||||
input[type="text"] {
|
|
||||||
margin-bottom: 20px;
|
|
||||||
padding: 10px;
|
|
||||||
width: 100%;
|
|
||||||
max-width: 400px;
|
|
||||||
}
|
|
||||||
</style>
|
|
||||||
</head>
|
|
||||||
<body>
|
|
||||||
<div class="container">
|
|
||||||
<h1 class="center-align">Core1.Doet.pixelHosting.nl ARP Table</h1>
|
|
||||||
|
|
||||||
<input type="text" id="arpSearch" placeholder="Search in ARP table..." onkeyup="filterTable('arpSearch', 'arpTable')">
|
|
||||||
<table class="striped" id="arpTable">
|
|
||||||
<thead>
|
|
||||||
<tr>
|
|
||||||
<th>Address</th>
|
|
||||||
<th>Interface</th>
|
|
||||||
<th>Link Layer Address</th>
|
|
||||||
<th>State</th>
|
|
||||||
</tr>
|
|
||||||
</thead>
|
|
||||||
<tbody>
|
|
||||||
{% for entry in arp_table %}
|
|
||||||
<tr>
|
|
||||||
<td>{{ entry.address }}</td>
|
|
||||||
<td>{{ entry.interface }}</td>
|
|
||||||
<td>{{ entry.link_layer_address }}</td>
|
|
||||||
<td>{{ entry.state }}</td>
|
|
||||||
</tr>
|
|
||||||
{% endfor %}
|
|
||||||
</tbody>
|
|
||||||
</table>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<!-- Footer -->
|
|
||||||
<footer></footer>
|
|
||||||
|
|
||||||
<!-- Materialize JS -->
|
|
||||||
<script src="https://cdnjs.cloudflare.com/ajax/libs/materialize/1.0.0/js/materialize.min.js"></script>
|
|
||||||
<script>
|
|
||||||
function filterTable(searchInputId, tableId) {
|
|
||||||
var input, filter, table, tr, td, i, j, txtValue;
|
|
||||||
input = document.getElementById(searchInputId);
|
|
||||||
filter = input.value.toUpperCase();
|
|
||||||
table = document.getElementById(tableId);
|
|
||||||
tr = table.getElementsByTagName("tr");
|
|
||||||
|
|
||||||
for (i = 1; i < tr.length; i++) {
|
|
||||||
tr[i].style.display = "none";
|
|
||||||
td = tr[i].getElementsByTagName("td");
|
|
||||||
for (j = 0; j < td.length; j++) {
|
|
||||||
if (td[j]) {
|
|
||||||
txtValue = td[j].textContent || td[j].innerText;
|
|
||||||
if (txtValue.toUpperCase().indexOf(filter) > -1) {
|
|
||||||
tr[i].style.display = "";
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
</script>
|
|
||||||
</body>
|
|
||||||
</html>
|
|
||||||
"""
|
|
||||||
|
|
||||||
template = Template(html_template)
|
|
||||||
html_output = template.render(arp_table=arp_table)
|
|
||||||
|
|
||||||
return html_output
|
|
||||||
|
|
||||||
@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)
|
|
||||||
|
|
||||||
@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)
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue