Netstat in python. Does it's possible?

Cameron Laird claird at lairds.us
Sun Feb 12 11:08:02 EST 2006


In article <43EE7B7E.5050802 at v.loewis.de>,
Martin v. Löwis <martin at v.loewis.de> wrote:
>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.
			.
			.
			.
ALSO, as you know, but billie might not, Python certainly makes
it easy enough to wrap netstat itself as an external executable.
In many situations, *that*'s the right solution.



More information about the Python-list mailing list