468,538 Members | 1,812 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 468,538 developers. It's quick & easy.

Socket Programming - Question

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 '06 #1
6 1245
du********@hotmail.com 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 '06 #2
On 2006-02-11, du********@hotmail.com <du********@hotmail.com> 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/li...#os-newstreams

--
Grant Edwards grante Yow! I'm not available
at for comment...
visi.com
Feb 11 '06 #3
D
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 :)

Feb 11 '06 #4
D
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?

Feb 11 '06 #5
"du********@hotmail.com" <du********@hotmail.com> 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/
Feb 11 '06 #6
On 2006-02-11, D <du********@hotmail.com> 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
Feb 11 '06 #7

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

2 posts views Thread by Jean-Philippe Guyon | last post: by
2 posts views Thread by dream machine | last post: by
1 post views Thread by John Sheppard | last post: by
5 posts views Thread by Justin Creasy | last post: by
2 posts views Thread by djc | last post: by
14 posts views Thread by =?Utf-8?B?TWlrZVo=?= | last post: by
3 posts views Thread by Stuart | last post: by
1 post views Thread by =?Utf-8?B?UmFqbmk=?= | last post: by
reply views Thread by NPC403 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.