init commit
This commit is contained in:
47
files/lldp-api.py
Normal file
47
files/lldp-api.py
Normal file
@ -0,0 +1,47 @@
|
||||
import requests
|
||||
import subprocess
|
||||
from lxml import html
|
||||
from flask import Flask, request, jsonify
|
||||
import json
|
||||
from datetime import datetime
|
||||
|
||||
app = Flask(__name__)
|
||||
|
||||
@app.route('/test', methods=['GET'])
|
||||
def test():
|
||||
return {"message": "Hello There"}
|
||||
|
||||
@app.route('/data', methods=['GET'])
|
||||
def get_data():
|
||||
return get_lldp_data()
|
||||
|
||||
def get_lldp_data():
|
||||
# Set commands here
|
||||
commands = {
|
||||
"switch_name": "lldpcli show neighbors | grep SysName | cut -d ':' -f 2 | tr -d ' '",
|
||||
"port_name": "lldpcli show neighbors | grep PortDes | cut -d ':' -f 2 | tr -d ' '",
|
||||
"port_speed": "ethtool eth0 | grep Speed | cut -d ':' -f 2 | tr -d ' '",
|
||||
"vlan_id": "lldpcli show neighbors details | grep VLAN | cut -d ':' -f 2 | cut -d ',' -f 1 | tr -d ' '"
|
||||
}
|
||||
|
||||
# Create an empty dictionary to store the results
|
||||
results = {}
|
||||
# Loop through the commands, run them, and store the output in the results dictionary
|
||||
for key, command in commands.items():
|
||||
try:
|
||||
# Run the command and capture the output
|
||||
result = subprocess.run(command, shell=True, capture_output=True, text=True)
|
||||
|
||||
# Store the output in the dictionary, removing any trailing newlines
|
||||
results[key] = result.stdout.strip()
|
||||
except Exception as e:
|
||||
# Handle any errors by storing the error message in the results
|
||||
results[key] = f"Error: {str(e)}"
|
||||
results['timestamp'] = datetime.now().strftime("%H:%M:%S")
|
||||
# Convert the results dictionary to a JSON string
|
||||
# json_output =
|
||||
return json.dumps(results, indent=4)
|
||||
|
||||
if __name__ == '__main__':
|
||||
app.run(debug=True, host='127.0.0.1', port=5000)
|
||||
|
||||
34
files/lldp-scan.py
Normal file
34
files/lldp-scan.py
Normal file
@ -0,0 +1,34 @@
|
||||
import requests
|
||||
import json
|
||||
from time import sleep
|
||||
from pitop import Pitop
|
||||
|
||||
pitop = Pitop()
|
||||
miniscreen = pitop.miniscreen
|
||||
miniscreen.display_multiline_text("Welcome to LLDP Scanner", font_size=14)
|
||||
sleep (1)
|
||||
|
||||
while not miniscreen.cancel_button.is_pressed:
|
||||
# Query LLDP API
|
||||
api_response = requests.get("http://127.0.0.1:5000/data")
|
||||
api_data = api_response.json()
|
||||
port_name = api_data['port_name']
|
||||
port_speed = api_data['port_speed']
|
||||
switch_name = api_data['switch_name']
|
||||
vlan_id = api_data['vlan_id']
|
||||
lldp_timestamp = api_data['timestamp']
|
||||
|
||||
# Display LLDP data
|
||||
miniscreen.display_multiline_text(f"LLDP Scan Taken {lldp_timestamp}", font_size=14)
|
||||
sleep(4)
|
||||
miniscreen.display_multiline_text(f"Port Name: {port_name}", font_size=12)
|
||||
sleep(4)
|
||||
miniscreen.display_multiline_text(f"Port Speed: {port_speed}", font_size=12)
|
||||
sleep(4)
|
||||
miniscreen.display_multiline_text(f"Switch Name: {switch_name}", font_size=12)
|
||||
sleep(4)
|
||||
miniscreen.display_multiline_text(f"VLAN ID: {vlan_id}", font_size=12)
|
||||
sleep(4)
|
||||
|
||||
miniscreen.display_multiline_text("Ending Application", font_size=14)
|
||||
sleep(2)
|
||||
Reference in New Issue
Block a user