Socket Programming - Question

Discussion in 'Python' started by duncanm255@hotmail.com, Feb 11, 2006.

  1. Guest

    I am relatively new to Python, and wanted to see if this is even
    possible, and if so how to go about implementing it. What I'm looking
    to do is create a client/server application that does the following:

    1) System2 listens on port > 1023
    2) System1 connects to System2 and sends traffic to it - based on the
    traffic it receives (i.e. a special string), System2 executes
    command-line commands and returns the output to System1.

    An example of what I am looking to use this for is for remote virus
    scanning. So System2 listens, System1 connects and sends it the
    traffic to start the scan, then System1 returns either what would be
    listed in the Command Prompt window, or possibly the contents of the
    logfile.

    Any help would be greatly appreciated!

    Doug
    , Feb 11, 2006
    #1
    1. Advertising

  2. Guest

    wrote:

    > An example of what I am looking to use this for is for remote virus
    > scanning. So System2 listens, System1 connects and sends it the


    Just found this through OSNews:
    http://rpyc.sourceforge.net/

    It actually seems to be a perfect fit for your job.

    Lorenzo
    , Feb 11, 2006
    #2
    1. Advertising

  3. On 2006-02-11, <> wrote:

    > I am relatively new to Python, and wanted to see if this is
    > even possible, and if so how to go about implementing it.
    > What I'm looking to do is create a client/server application
    > that does the following:
    >
    > 1) System2 listens on port > 1023
    > 2) System1 connects to System2 and sends traffic to it - based on the
    > traffic it receives (i.e. a special string), System2 executes
    > command-line commands and returns the output to System1.


    Sure. Just use os.popen() or one of it's relatives to execute
    the program:

    http://www.python.org/doc/current/lib/os-newstreams.html#os-newstreams

    --
    Grant Edwards grante Yow! I'm not available
    at for comment...
    visi.com
    Grant Edwards, Feb 11, 2006
    #3
  4. D Guest

    Thanks! Now, I'm a bit confused as to exactly how it works - will it
    display the output of what it executes on the target system? I would
    like to create a window in Tktinker to where a user can select options
    (such as run scan on remote system) - it would then run the
    command-line based scan and return the output. Does this sound like
    something it would do? Thanks again :)
    D, Feb 11, 2006
    #4
  5. D Guest

    I've used os.popen() before, but if I execute it on a remote system how
    could I get the output back to the requesting machine?
    D, Feb 11, 2006
    #5
  6. Paul Rubin Guest

    "" <> writes:
    > I am relatively new to Python, and wanted to see if this is even
    > possible, and if so how to go about implementing it. What I'm looking
    > to do is create a client/server application that does the following:
    >
    > 1) System2 listens on port > 1023
    > 2) System1 connects to System2 and sends traffic to it - based on the
    > traffic it receives (i.e. a special string), System2 executes
    > command-line commands and returns the output to System1.


    You're asking how to write a TCP server in general. You might look at
    the SocketServer module in the standard library, which gives a
    reasonable framework for that kind of server. However, its
    documentation is not very good. Alex Martelli's "Python Cookbook" may
    have some better examples.

    If you want your server to be able to handle multiple client sessions
    simultaneously, use SocketServer.ThreadingMixin (for multiple threads)
    or SocketServer.ForkingMixin (multiple processes). Beware that this
    stuff is not easy for beginners, unless you've had experience writing
    servers in other languages (maybe Java).

    There's another issue too, especially if your app is a virus scanner:
    you have to think very hard about what happens if a malicious client
    connects to your server (a virus scanning app is an unusually juicy
    target for such attacks). It's extremely easy to leave security holes
    open (the viruses themselves typically exploit such holes in Windows)
    so you have to develop a paranoid attitude about what kinds of things
    the attacker can try and how you can defend. Using Python puts you
    one step ahead of Windows, since you're mostly immune to buffer
    overflow bugs, a very common vulnerability. But it's still an area
    full of hazards and not so good for beginners.

    This is good bedtime reading: http://www.dwheeler.com/secure-programs/
    Paul Rubin, Feb 11, 2006
    #6
  7. On 2006-02-11, D <> wrote:

    > I've used os.popen() before, but if I execute it on a remote
    > system how could I get the output back to the requesting
    > machine?


    Write it to the socket?

    --
    Grant Edwards grante Yow! Where does it go when
    at you flush?
    visi.com
    Grant Edwards, Feb 11, 2006
    #7
    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. Laszlo Nagy
    Replies:
    1
    Views:
    4,811
    Mark Wooding
    Jan 27, 2009
  2. Jean-Paul Calderone
    Replies:
    0
    Views:
    962
    Jean-Paul Calderone
    Jan 27, 2009
  3. Laszlo Nagy
    Replies:
    0
    Views:
    542
    Laszlo Nagy
    Feb 1, 2009
  4. Steve Holden
    Replies:
    0
    Views:
    659
    Steve Holden
    Feb 1, 2009
  5. Steve Holden
    Replies:
    1
    Views:
    714
Loading...

Share This Page