Created
February 17, 2019 18:49
-
-
Save petrilgner/3f9f970e995ea52c5e5228e8114fbde3 to your computer and use it in GitHub Desktop.
A brief script for visualizing the RouterOS mangle rule traffic using TK framework
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from librouteros import connect | |
from tkinter import * | |
ROUTER_API_IP = '192.168.1.1' | |
ROUTER_API_PORT = '8728' | |
ROUTER_API_USER = 'admin' | |
ROUTER_API_PASSWORD = 'pwd' | |
ROUTER_MANGLE_UPLOAD = 'UPLOAD' | |
ROUTER_MANGLE_DOWNLOAD = 'DOWNLOAD' | |
api = connect(host=ROUTER_API_IP, username=ROUTER_API_USER, password=ROUTER_API_PASSWORD, port=ROUTER_API_PORT) | |
def task(): | |
out = api(cmd='/ip/firewall/mangle/print') | |
for value in out: | |
if value['comment'] == ROUTER_MANGLE_UPLOAD: | |
val = int(value['bytes']) / 1024 / 1024 | |
upl.set("%.2f MB" % val) | |
if value['comment'] == ROUTER_MANGLE_DOWNLOAD: | |
val = int(value['bytes']) / 1024 / 1024 | |
down.set("%.2f MB" % val) | |
top.update() | |
top.after(400, task) | |
# GUI definition | |
top = Tk() | |
down = StringVar() | |
upl = StringVar() | |
text1 = Label(top, textvariable=down, font="Tahoma 120 bold", fg="darkgreen", ) | |
text2 = Label(top, textvariable=upl, font="Tahoma 60 bold", fg="blue") | |
text1.pack() | |
text2.pack() | |
down.set("---") | |
upl.set("---") | |
top.after(100, task) | |
top.mainloop() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment