Socket Programming - Question

D

duncanm255

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
 
L

lbolognini

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 OShttp://rpyc.sourceforge.net/

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

Lorenzo
 
G

Grant Edwards

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
 
D

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 :)
 
D

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?
 
P

Paul Rubin

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/
 
G

Grant Edwards

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?
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,767
Messages
2,569,572
Members
45,046
Latest member
Gavizuho

Latest Threads

Top