billie wrote:
> Hi all. I don't know if Python is good for this kind of jobs but I'm 
> wondering if it's possible emulate the "netstat" command in Python.

As a general recommendation, use strace(1) to answer this kind of
question. Run "strace -o tmp netstat", then inspect tmp to find out
how netstat obtained the information it reported.

As Sybren suggests, this can all be answered from /proc. For a
process you are interested in, list /proc/<pid>/fd (using os.listdir),
then read the contents of all links (using os.readlink). If the link
value starts with "[socket:", it's a socket. Then search
/proc/net/tcp for the ID. The line containing the ID will have
the information you want.

Regards,
Martin
-- 
http://mail.python.org/mailman/listinfo/python-list

Reply via email to