Nixellion / MikrotikTrafficMonitor

A small server that keeps track of traffic usage per IP for RouterOS
MIT License
27 stars 6 forks source link

I want to ask that I have turned off fast traffic, but I still can’t record traffic #5

Open wartw opened 3 years ago

wartw commented 3 years ago

I want to ask that I have turned off fast traffic, but I still can’t record traffic

Nixellion commented 3 years ago

I think you need to turn Accounting on as well

wartw commented 3 years ago

Python cannot parse and process normally, I am sure all ros have normal output

Nixellion commented 3 years ago

What do you mean "Python cannot parse and process normally"? Are there any errors in console?

I never said they have different output, but you do need to disable Fast Track, enable Accounting, enable Web Access to Accounting and type the IP of the PC where you run TrafficMonitor on, otherwise ROS will block it from access.

wartw commented 3 years ago

I will show you a screenshot later

wartw commented 3 years ago

未命名1

Nixellion commented 3 years ago

Sorry, not sure what's wrong?

It only shows local clients in LAN, which is what it's for.

wartw commented 3 years ago

All of my network is running nat, I want to check the usage of each area IP

Nixellion @.***> 於 2021年5月11日 週二 上午6:22 寫道:

Sorry, not sure what's wrong?

It only shows local clients in LAN, which is what it's for.

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/Nixellion/MikrotikTrafficMonitor/issues/5#issuecomment-837429723, or unsubscribe https://github.com/notifications/unsubscribe-auth/ADV2U5SGAUA7YNBC62QKRDLTNBMDFANCNFSM44P66M7Q .

Nixellion commented 3 years ago

Well, in it's current state this project only supports single subnet based on router's IP. I developed it for simple use at home environment where it's unlikely you would have that many networks or extra NAT rules.

The key here is that the data mask of Mirkotik's accounting is source ip, destination ip, x, x, x, x and it lists all connections as they were initiated or something like that, meaning that source ip is not necessarily your local one. So it has to be filtered.

You can see the relevant code in this file and try updating or changing it to adapt to your needs: https://github.com/Nixellion/MikrotikTrafficMonitor/blob/master/collector.py

All the code responsible for getting and parsing data from mirkotik's accounting table is in this file.

So instead of using these checks:

if src.startswith(self.local_network):  # upload
                k = src
elif dst.startswith(self.local_network):

You may replace it with:

if   ".".join(src.strip().split('.')[0:-1]) in self.local_networks:  # upload
                k = src
elif ".".join(dst.strip().split('.')[0:-1]) in self.local_networks:

And also on line 17 you'd need to replace or add below a new variable:

self.local_networks = ["192.168.1.", "192.168.2."]  # List any subnet parts you'd like to track

Something like that would work.

Sadly I don't have the time to actively maintain this project and implement these updates myself, it outlived it's usefulness for me, but that's why I made it open source, so anyone can pick it up and improve on it as needed.

wartw commented 3 years ago

Thanks

Nixellion @.***> 於 2021年5月11日 週二 下午4:56 寫道:

Well, in it's current state this project only supports single subnet based on router's IP. I developed it for simple use at home environment where it's unlikely you would have that many networks or extra NAT rules.

The key here is that the data mask of Mirkotik's accounting is source ip, destination ip, x, x, x, x and it lists all connections as they were initiated or something like that, meaning that source ip is not necessarily your local one. So it has to be filtered.

You can see the relevant code in this file and try updating or changing it to adapt to your needs: https://github.com/Nixellion/MikrotikTrafficMonitor/blob/master/collector.py

All the code responsible for getting and parsing data from mirkotik's accounting table is in this file.

So instead of using these checks:

if src.startswith(self.local_network): # upload k = srcelif dst.startswith(self.local_network):

You may replace it with:

if ".".join(src.strip().split('.')[0:-1]) in self.local_networks: # upload k = srcelif ".".join(dst.strip().split('.')[0:-1]) in self.local_networks:

And also on line 17 you'd need to replace or add below a new variable:

self.local_networks = ["192.168.1.", "192.168.2."] # List any subnet parts you'd like to track

Something like that would work.

Sadly I don't have the time to actively maintain this project and implement these updates myself, it outlived it's usefulness for me, but that's why I made it open source, so anyone can pick it up and improve on it as needed.

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/Nixellion/MikrotikTrafficMonitor/issues/5#issuecomment-838104257, or unsubscribe https://github.com/notifications/unsubscribe-auth/ADV2U5QAIKVXU74BJRPKYV3TNDWK5ANCNFSM44P66M7Q .