Map port to process

Discussion in 'Python' started by py, Jan 5, 2006.

  1. py

    py Guest

    Is there a way in python to figure out which process is running on
    which port? I know in Windows XP you can run "netstat -o" and see the
    process ID for each open port....but I am looking for something not
    tied to windows particularly, hopefully something in python.

    if not, any known way, such as netstat shown above, for other versions
    of windows (such as 98, 2000) and even linux?

    thanks
    py, Jan 5, 2006
    #1
    1. Advertising

  2. py wrote:

    > Is there a way in python to figure out which process is running on
    > which port? I know in Windows XP you can run "netstat -o" and see the
    > process ID for each open port....but I am looking for something not
    > tied to windows particularly, hopefully something in python.
    >
    > if not, any known way, such as netstat shown above, for other versions
    > of windows (such as 98, 2000) and even linux?


    Linux also knows netstat.

    And at least with on-board mechanisms (meaning the standard lib), I fear you
    can only try and use netstat as subprocess.

    I'm not aware of an extension module that does what you want, but I didn't
    google for it.

    Diez
    Diez B. Roggisch, Jan 5, 2006
    #2
    1. Advertising

  3. py

    Mike Meyer Guest

    "py" <> writes:
    > Is there a way in python to figure out which process is running on
    > which port? I know in Windows XP you can run "netstat -o" and see the
    > process ID for each open port....but I am looking for something not
    > tied to windows particularly, hopefully something in python.


    Well, once you get to "no tied to an OS", you're out of luck. You can
    run network stacks on systems that don't have processes, so there's no
    general mechanism for getting process information from a
    socket. Restricting things to posixish systems doesn't seem to help
    much, as there doesn't seem to be a posix interface to get it either.

    > if not, any known way, such as netstat shown above, for other versions
    > of windows (such as 98, 2000) and even linux?


    Many windows networking tools started life as Unix networking
    tools. Netstat is one of them. The -o flag may be a Windows addition,
    though. FreeBSD (for instance) doesn't have it, but provides the
    sockstat command to get pid/process name/etc. info on
    sockets. Sockstat uses sysctls to pull specific kernel structures,
    which means it's OS-specific. Python doesn't seem to have a way to do
    sysctl calls, either.

    <mike
    --
    Mike Meyer <> http://www.mired.org/home/mwm/
    Independent WWW/Perforce/FreeBSD/Unix consultant, email for more information.
    Mike Meyer, Jan 5, 2006
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. John T. Goodman

    Overhead of 4-port over 2-port SRAM

    John T. Goodman, Jan 25, 2005, in forum: VHDL
    Replies:
    0
    Views:
    586
    John T. Goodman
    Jan 25, 2005
  2. Sean Wolfe
    Replies:
    1
    Views:
    2,236
    Joerg Jooss
    Apr 28, 2005
  3. b3ny
    Replies:
    11
    Views:
    907
    Babu Kalakrishnan
    Nov 20, 2004
  4. Vindog67

    Port map with if and process

    Vindog67, Oct 12, 2011, in forum: VHDL
    Replies:
    0
    Views:
    979
    Vindog67
    Oct 12, 2011
  5. revanthb3000

    Using port map in a process

    revanthb3000, Nov 10, 2011, in forum: VHDL
    Replies:
    1
    Views:
    1,543
    jeppe
    Nov 11, 2011
Loading...

Share This Page