shadyabhi / who-ate-my-bandwidth

This script reads realtime bandwidth usage for devices connected to netgear routers and updates that data in Redis.
0 stars 1 forks source link

It is not a problem, I want to contact the author. #1

Open qrczepieczone opened 3 years ago

qrczepieczone commented 3 years ago

Hello Abhijeet!

I have a problem with your script in python (and go). When I debug the python script, I can see that Ip is collected but (I am a weak programmer) I can't use it to print it (I know why you uses mac address, but I have static IP for each device in my LAN network, so I can count traffic by IP number).

Could you give me a hint, how print IP number instead of mac (or how I can use both)?

By the way - great script I use it on Netgear D7800 and it works flawlessly.

Sorry for my English I don't use it often.

Best regards, Robert

shadyabhi commented 3 years ago

Hi Robert,

Thanks for reaching out. The router that I tested against it put somewhere in storage at the moment since I moved to Ubiquiti devices. Having said that, I can help you if you help me in providing some more details on what part are you stuck on.

As the first step, can you help in providing the response that you get from the API calls? Once you list them here, I can help you provide a direction. There are 2 API calls, get_device_names and get_current_flow.

Thank you.

shadyabhi commented 3 years ago

Hey Robert,

Since this was written 4 years ago, I wanted to confirm, are you able to get the dashboard working, meaning do the API calls work as intended even after 4 years?

Thanks you.

qrczepieczone commented 3 years ago

Hey Abhijeet!

Thank You for answering!

Yes! Everything works, without any corrections on my part - great job :) .

I'll send the answers from API on Monday/Tuesday.

Look how your child spits out the data: screenPython

And your web :) : screenWeb

qrczepieczone commented 3 years ago

Ok, I've got it:

get_device_names returns:

screenGetDeviceNames

and get_current_flow returns:

getCurrentFlow

shadyabhi commented 3 years ago

@qrczepieczone Apologize for delayed response. Thanks for providing the responses. It looks like only MAC addresses are provided in the API response, not IP addresses.

That means, we need to leverage things outside of the API to do it.

One common way to get the IP address to MAC mapping in the local area network is running this command from a machine in the same network.

$ip neigh show

image

Other ways of doing it by actually scanning your local network to see the most recent data. https://stackoverflow.com/a/42520995/167814

qrczepieczone commented 3 years ago

@shadyabhi don't worry everybody has own life ;)

I think API gives us info about IP - tomorrow I will send you a screen from a debugger.

qrczepieczone commented 3 years ago

Sorry, I had a lot of work to do and forgot about my promise.

When You call _get_current_flow(self)

def get_current_flow(self): current_flows = dict() response = self._call('http://192.168.1.1/cgi-bin/' 'ozker/api/flows?ts=%d'.format( int(time.time() * 1000))) for flow in response['flows']: current_flows[flow['uid']] = dict(up_bytes=flow['up_bytes'], down_bytes=flow['down_bytes'], mac=flow['mac']) return current_flows

the answer looks like this:

screen1Python screen2Python

As you can see, we have more data even such as:

destination IP source IP ports and more.

Now I'm trying to rewrite this script and add data to INFLUXdb to view the results in Grafana.

Best regards, Robert

qrczepieczone commented 3 years ago

I did it. :) :) :) I'm so happy.

I reworked your script, added saving to MySQL database (I didn't know how to use Redis in time series charts), and here's the effect in graphing.

Thanks for publishing your script - it was a big inspiration. screenPytRt

shadyabhi commented 3 years ago

@qrczepieczone Wow, this is great. If I were to do this again, I would use your approach of using Grafana :) 💯

If you're hosting the code somewhere, feel free to link it here. Thanks!