0

I’m trying to build a python command-line program that monitors all available network interfaces in a machine. Similar to the popular (nload) which monitors the network bandwidth per interface, and (nethogs) commands which monitor network bandwidth per process I want to build a program that combine both options and also produce colored output.

nload

nload

nethogs

nethogs

My question is, how can I interact directly with the network interface from within python code? Is there a way to identity incoming/outgoing bandwidth speed? Is there a specific library that is recommended?

3
  • 1
    pypi.python.org/pypi/pypcap Commented Mar 23, 2015 at 16:20
  • Thanks. However, there are similar libraries out there pcapy being one of them. What makes pypcap better. Can you shed some light on this matter Commented Mar 23, 2015 at 16:30
  • 1
    nethogs uses libpcap so I imagine you can get the same kind of functionality using it. Commented Mar 23, 2015 at 16:31

1 Answer 1

1

Your question is highly OS depended. You will need other ways to access the interface statistics on different operating systems.

From your screenshot I guess that you might want to use Linux. In that case collecting the data from /sys/class/net/, /proc/net/, /proc/[pid]/net and /proc/sys/net would be a good start. There are tons of value to make statistics from.

For the terminal output you should have a look at curses.

Sign up to request clarification or add additional context in comments.

2 Comments

You're absolutely right! Sorry I didn't clarify that in my question. I'm targeting unix-like machines (Linux and OSX). The paths you provided maybe valid for Linux systems but they are not available on OSX. Do you have any idea where I can locate the same on OSX? I also should note that I'm using the Urwid terminal interface library. It's a clean API that sits on top of ncurses for building terminal interfaces.
On MacOS you have to use sysctl - somehow. I imaging a OS X experienced developer can tell you more…

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.