Thread: using netstat

    #1
  1. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Mar 2004
    Posts
    49
    Rep Power
    11

    using netstat


    Hi All,

    I'm new to python and I have a problem to solve using python:

    Basically, I want to write a small program, which runs on a designated port, and returns a complete listing of all network connections (using netstat) back to the designated port.

    From my limited experience with Python I assume I need to:
    1. import socket library
    2. create a stream socket
    3. open a specific port for connections
    4. tell the socket to wait & listen for clients
    5. during this time I accept client connections & grab network info using netstat
    6. close the connection when done

    Any help would be gratefully appreciated.

    Cheers.
  2. #2
  3. Hello World :)
    Devshed Frequenter (2500 - 2999 posts)

    Join Date
    Mar 2003
    Location
    Hull, UK
    Posts
    2,537
    Rep Power
    69
    Makes sense, you could also create a web service although thats probably overkill depending on what your doing. In either case you should use the subprocess module to get the results from 'netstat'. Here are a few links that you might find useful:

    http://www.python.org/doc/2.4/lib/module-subprocess.html
    http://www.python.org/doc/2.4/lib/module-socket.html
    http://www.devshed.com/c/a/Python/Sockets-in-Python/
    http://www.devshed.com/c/a/Python/The-Python-Web-Services-Developer-Part-1/
    http://www.devshed.com/c/a/Python/The-Python-Web-Services-Developer-Part-2/
    http://www.devshed.com/c/a/Python/The-Python-Web-Services-Developer-Part-3/
    http://pywebsvcs.sourceforge.net/

    If you have any questions ask away,

    Mark.
    programming language development: www.netytan.com Hula

  4. #3
  5. No Profile Picture
    Contributing User
    Devshed Intermediate (1500 - 1999 posts)

    Join Date
    Feb 2004
    Location
    London, England
    Posts
    1,585
    Rep Power
    1373
    Alternatively you could run it as an XML-RPC service. This would enable you to use SimpleXmlRpcServer to handle all the low-level code, and it would be callable from any language that supported XML-RPC.

    DAve - The Developers' Coach

IMN logo majestic logo threadwatch logo seochat tools logo