Skip to content

Instantly share code, notes, and snippets.

@petrilgner
Created February 17, 2019 18:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save petrilgner/3f9f970e995ea52c5e5228e8114fbde3 to your computer and use it in GitHub Desktop.
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
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