python socket proxy

J

jstobbs

Hi all

I am trying to create a lighweight tcp proxy server.

I got this code from ActivePython documentation.
What I am trying to accomplish, is I need to connect to local instance
of the proxyserver (127.0.0.1). This server must then connect to a
remote jabber server, send data, and listen to incoming data. When data
arrives, it must relay it back thru 127.0.0.1. The reason why I need I
am trying to get this to work, is I eventually want to make this server
connect over ssl/tls (which macromedia flash doesnt support natively).

The existing code only echoes back what it gets in, and note what it
gets back from the remote server. Help would be appreciated

Code:
# Echo server program
import socket

HOST = '127.0.0.1'                 # Symbolic name meaning the local
host
PORT = 50007              # Arbitrary non-privileged port
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.bind((HOST, PORT))
s.listen(1)
conn, addr = s.accept()
print 'Connected by', addr
while 1:
    data = conn.recv(1024)
    print (data)
    if not data: break
    conn.send(data)
conn.close()


# Echo client program
import socket

HOST = 'remoteserver.com'    # The remote host
PORT = 5222              # The same port as used by the server
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.connect((HOST, PORT))
s.send('Hello, world')
data = s.recv(1024)
print data
s.close()
print 'Received', repr(data)

thanks
 
F

Filip Wasilewski

J

jstobbs

Hi

Thanks for the reply.

I found a proxy that works for me. Now I would like to know if its
possible to run a python script, so its not visible in the cmd window
(windows, i know, its bad :) ) Maybe run it as a windows service?



Filip said:
Hi all

I am trying to create a lighweight tcp proxy server.
[...]

There is a bunch of nice recipies in the Python Cookbook on port
forwarding. In the [1] and [2] case it should be fairly simple to add
an extra authentication step with pyOpenSSL.

[1] http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/483730
[2] http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/114642
[3] http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/483732

best,
fw
 
J

Jeethu Rao

Simplest way would be to rename your python file with a .pyw extension
instead of a .py extension.
If you're looking for windows services, checkout
win32serviceutil.ServiceFramework in pywin32.

Jeethu Rao

Hi

Thanks for the reply.

I found a proxy that works for me. Now I would like to know if its
possible to run a python script, so its not visible in the cmd window
(windows, i know, its bad :) ) Maybe run it as a windows service?



Filip said:
Hi all

I am trying to create a lighweight tcp proxy server.
[...]

There is a bunch of nice recipies in the Python Cookbook on port
forwarding. In the [1] and [2] case it should be fairly simple to add
an extra authentication step with pyOpenSSL.

[1] http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/483730
[2] http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/114642
[3] http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/483732

best,
fw
 
J

jstobbs

cool, nice one, thanks.


Jeethu said:
Simplest way would be to rename your python file with a .pyw extension
instead of a .py extension.
If you're looking for windows services, checkout
win32serviceutil.ServiceFramework in pywin32.

Jeethu Rao

Hi

Thanks for the reply.

I found a proxy that works for me. Now I would like to know if its
possible to run a python script, so its not visible in the cmd window
(windows, i know, its bad :) ) Maybe run it as a windows service?



Filip said:
(e-mail address removed) wrote:

Hi all

I am trying to create a lighweight tcp proxy server.

[...]

There is a bunch of nice recipies in the Python Cookbook on port
forwarding. In the [1] and [2] case it should be fairly simple to add
an extra authentication step with pyOpenSSL.

[1] http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/483730
[2] http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/114642
[3] http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/483732

best,
fw
 

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,772
Messages
2,569,588
Members
45,100
Latest member
MelodeeFaj
Top