Netstat in python. Does it's possible?
"Martin v. Löwis"
martin at v.loewis.de
Sat Feb 11 19:04:14 EST 2006
Jorgen Grahn wrote:
> There might still be a problem for people doing things like this: netstat
> might use unstable or non-public APIs to find the things it lists. This is
> fine because it's typically your OS vendor who have to handle that (ship
> another netstat when the /proc or /sys file system layout changes, etc).
Right. However, on Unix, there aren't really that much "non-public"
APIs. If you can figure out what the system call number is, and you
have /usr/include/sys, you can typically come up with a way to call
this API.
It becomes tricky if netstat turns out to read /dev/kmem or some such.
> If it works like that, you can access the APIs fine from Python -- but you
> cannot write a portable 'pynetstat' without a lot of effort and maintenance.
Well, to make that accessible from Python, you need to have Python
wrappers for all system calls involved (or for library routines that
use the system calls the right way). In case of /proc, this is easy;
if it is a ioctl(2), it might still be doable. If it is something
else, you may have to write a Python wrapper for that other system
call first.
Regards,
Martin
More information about the Python-list
mailing list